簡體   English   中英

表單身份驗證在Internet Explorer上不起作用

[英]Forms authentication is not working on Internet Explorer

我無法使用Internet Explorer的表單身份驗證登錄到服務器上的我的MVC3網站。

我的ASP.NET MVC3網站使用表單身份驗證。 通過Internet Explorer使用網站時,在身份驗證方面遇到問題。

如果我從本地(開發環境或具有遠程桌面連接的托管服務器計算機)使用站點,則登錄沒有問題。 但是,當我嘗試從本地計算機登錄到服務器上的網站時,我無法通過登錄頁面。

嘗試更改即允許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>

任何想法都會被應用,因為我沒有想法。

謝謝閱讀。

這是ie10的一個已知錯誤( IE10 User-Agent導致ASP.Net不發回Set-Cookie(IE10未設置cookie) )。

我已經將此( http://support.microsoft.com/kb/2600088 )修補程序安裝到服務器,並且問題已解決。 但是請注意,此修復程序可能/將重置您的iis擴展設置和通配符應用映射。

因此,如果您使用的是MVC,則在安裝此修補程序后,請按照此( MVC3發布和IIS 6 )問題的答案上列出的說明進行操作。 為了能夠修復“目錄列表被拒絕”錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM