【问题标题】:Forms authentication is not working on Internet Explorer表单身份验证在 Internet Explorer 上不起作用
【发布时间】:2013-07-24 10:48:37
【问题描述】:

我无法通过 Internet Explorer 的表单身份验证登录到位于服务器上的 MVC3 网站。

我的 ASP.NET MVC3 网站使用表单身份验证。通过 Internet Explorer 使用该站点时,我遇到了身份验证问题。

如果我从本地(开发环境或从具有远程桌面连接的托管服务器计算机)使用站点,则登录没有问题。但是当我尝试从本地机器登录到位于服务器上的网站时,我无法通过登录页面。

尝试更改 ie 安全和隐私选项以允许 cookie,将我的域添加到信任域。但我仍然无法通过登录页面。

这是我在所有身份验证检查(用户名、密码等)后的登录代码

...
string userDataString = userid.ToString();

HttpCookie authCookie = FormsAuthentication.GetAuthCookie(username, rememberme);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userDataString);

authCookie.Value = FormsAuthentication.Encrypt(newTicket);
Response.Cookies.Add(authCookie);

if (Url.IsLocalUrl(returnurl) &&
    returnurl.Length > 1 &&
    returnurl.StartsWith("/") &&
    !returnurl.StartsWith("//") &&
    !returnurl.StartsWith("/\\") &&
    returnurl.IndexOf("XMLHttpRequest") < 0)
{
    return Redirect(returnurl);
}
else
{
    return Redirect("/");
}

...

和 web.config

<?xml version="1.0" encoding="utf-8"?>
...
<configuration>
  <connectionStrings>
    <add name="*******" connectionString="******" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
    <customErrors mode="Off" defaultRedirect="/Error/General">
      <error statusCode="403" redirect="/Error/NoAccess" />
      <error statusCode="404" redirect="/Error/NotFound" />
    </customErrors>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Authentication" timeout="2880" />
    </authentication>

    <machineKey validationKey="*********" decryptionKey="**************" validation="SHA1" decryption="AES" />

    <membership defaultProvider="TestMembershipProvider">
      <providers>
        <clear />
        <add name="TestMembershipProvider" type="Test.Helpers.TestMembershipProvider" connectionStringName="TestContext" />
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="TestRoleProvider" cacheRolesInCookie="true" cookieName="AppRoles" cookieTimeout="20" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
      <providers>
        <clear />
        <add name="TestRoleProvider" type="Test.Helpers.TestRoleProvider" connectionStringName="TestContext" applicationName="/" />
      </providers>
    </roleManager>

    ...

  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>

任何想法都会得到认可,因为我已经没有想法了。

感谢阅读。

【问题讨论】:

    标签: asp.net asp.net-mvc-3 internet-explorer forms-authentication


    【解决方案1】:

    这是 ie10 (IE10 User-Agent causes ASP.Net to not send back Set-Cookie (IE10 not setting cookies)) 的一个已知错误。

    我已将这个(http://support.microsoft.com/kb/2600088) 修补程序安装到服务器,问题已解决。但请注意,此修复可能/将重置您的 iis 扩展设置和通配符应用映射。

    因此,如果您使用 MVC,请在安装修补程序后按照此 (MVC3 publishing and IIS 6) 问题的答案中列出的说明进行操作。能够修复“目录列表被拒绝”错误。

    【讨论】:

    • 似乎 web.config 修复对我来说是正确的修复......你的 SO 链接帮助找到它......谢谢 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多