表单身份验证在本地工作,但不在开发服务器上

问题描述:

我知道表单身份验证是旧的,但是当我使用IIS Express在本地运行Web应用程序时,一切正常。但是当我将它发布到我们的开发/测试服务器时,它只是重新加载页面。开发服务器正在运行IIS 6.表单身份验证在本地工作,但不在开发服务器上

还有一点需要注意,本地它运行为localhost:50264/Login。在开发服务器上,url更像是http://dev1.server.com/op/webapp/Account/Login

我注意到这两个cookie都有路径“/”。我曾尝试设置的变化,通过在我的本地web.config中有这样的:

<add key="CookiePath" value="/" /> 

,然后当我发布到它changest到我们的开发服务器:好像还是

<add key="CookiePath" value="http://dev1.server.com/op/webapp/" xdt:Transform="Replace" xdt:Locator="Match(key)" /> 

不是工作。

在另一个线程我在堆栈溢出发现,有人建议将它添加到:

<system.webServer> 
    <modules> 
     <add name="FormsAuthenticationModule" type="System.Web.Security.FormsAuthenticationModule" /> 
    </modules> 
</system.webServer> 

这也不能工作。任何帮助将不胜感激!

UPDATE:2016年9月29日

我除去CookiePath应用设置和,而不是做了调整到认证节点。在我的web.config我现在有:

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/Login" timeout="2880" requireSSL="false" slidingExpiration="true" path="/" /> 
</authentication> 

在我Web.Debug.config我:

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/Login" timeout="2880" requireSSL="false" slidingExpiration="true" path="/op" xdt:Transform="Replace" /> 
</authentication> 

最后,当我创建cookie的:

var authTicket = new FormsAuthenticationTicket(
    1, 
    user.Email, 
    DateTime.Now, 
    DateTime.Now.AddDays(14), 
    true, 
    userData, 
    FormsAuthentication.FormsCookiePath); 

当我部署到开发服务器,我在那里检查web.config,它确实正确地转换了表单节点。

当我去登录时,我输入我的凭据,它仍然刷新登录页面。使用Chrome扩展“EditThisCookie”,我仍然可以看到cookie的路径是“/”。它不能识别AT ALL的变化。即使我手动将authTicket路径的路径设置为“/ op”,cookie STILL的路径也为“/”。我不知道发生了什么事。呃...

+0

什么是'CookiePath'?它如何与你的形式cookies相关?它看起来不像内置基础架构的一部分。 –

+0

无论是本地还是开发者服务器上,它都有正确的域名,但路径始终为“/” – ajtatum

+0

您在这里所拥有的就是看起来像是从appSettings部分中删除的帽子。我试图告诉你的是,没有内置的机制,这种任意设置与表单身份验证相关。 –

我也使用表单身份验证,这里是我的设置。你没有显示你所有的表单验证码,但希望这会指出你在正确的方向。

的Web.Config

<authentication mode="Forms"> 
    <forms loginUrl="members/login.aspx" name=".ASPXFORMSAUTH" requireSSL="false" slidingExpiration="true" timeout="120" /> 
</authentication> 

然后,我在代码中设置cookie的后面时英寸

Dim authCookie As HttpCookie = FormsAuthentication.GetAuthCookie(iMembersID, False) 
    Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(authCookie.Value) 
    Dim newTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, "Member") 
    authCookie.Value = FormsAuthentication.Encrypt(newTicket) 
    Response.Cookies.Add(authCookie) 

用户登录然后我测试,看看他们在需要的所有页面认证要登录的用户。

If Request.IsAuthenticated Then 
     Dim ident As FormsIdentity = CType(User.Identity, FormsIdentity) 
     If ident IsNot Nothing Then 

      Dim ticket As FormsAuthenticationTicket = ident.Ticket 
      Dim userDataString As String = ticket.UserData 

      Select Case ticket.UserData 
       Case "Member" 
        m_MemberLoggedIn = ident.Name 
       Case Else 
        Response.Redirect("~/members/login/", True) 
      End Select 


     Else 
      Response.Redirect("~/members/login/", True) 
     End If 

更新9/29:

检查以确保IIS身份验证模式设置为匿名

+0

由于您似乎正在使用WebForms,因此这里是WebForms授权文档的链接https://msdn.microsoft.com/en-us/library/wce3kxhd.aspx –

+0

每一页都没有被选中,只是页面需要授权(这就是表单身份验证的工作原理)。 OP问题是关于表单身份验证和他有问题。这不是一个问题,关于如何处理认证最好的方法是什么,这将是一个漫长的讨论。 – Henry

+0

我对web config和Authentication Ticket进行了更改,这对dev服务器没有任何帮助。 – ajtatum

我走出去的简单的方法,并要求我们的IT部门创建一个子域等等cookie的路径将始终为“/”。没有答案,但这是我做的。