我无法使用 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>
任何想法都会被应用,因为我已经没有想法了。
谢谢阅读。