表单身份验证不适用于Internet Explorer

时间:2013-07-24 10:48:38

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

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

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

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

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

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

...
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>

任何想法都会受到影响,因为我没有想法。

感谢阅读。

1 个答案:

答案 0 :(得分:2)

这是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)问题的答案中列出的说明进行操作。能够修复“目录列表被拒绝”错误。