asp.net-mvc - ASP.Net MVC 应用程序注销未完全注销

标签 asp.net-mvc session authentication asp.net-mvc-4 forms-authentication

此应用程序运行的环境中,一些用户仍在使用 IE7(如果这有什么区别的话)。我们偶尔会看到,在某人注销而其他人登录后,他们仍然会收到前一个人的残留信息,其中可能会显示该人的个人资料。任何建议将不胜感激。

我在我的 asp.net mvc 应用程序中使用以下方法作为注销方法

public ActionResult LogOff()
{

    System.Web.HttpContext.Current.Response.Cookies.Clear();
    FormsService.SignOut();
    Session["User"] = null;
    Session.Clear();
    Session.Abandon();
    Session.RemoveAll();

    return Redirect("/");
}

该应用正在使用保存到数据库中的 session ,因为它在两个不同的 Web 服务器上运行。

这是 web.config 中的一些设置

<sessionState sqlConnectionString="LiveDB" />
<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
  <providers>
    <clear />
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LiveDB" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="50" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
  </providers>
</membership>
<profile>
  <providers>
    <clear />
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="LiveDB" applicationName="/" />
  </providers>
</profile>
<roleManager enabled="true">
  <providers>
    <clear />
    <add connectionStringName="LiveDB" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
    <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
  </providers>
</roleManager>

最佳答案

如果您使用 FormAuthentication 像这样登录 -

FormsAuthentication.SetAuthCookie("username", false);

那么注销应该是

FormsAuthentication.SignOut();

如果仍有问题,您可以强制 cookie 过期,如 this .

关于asp.net-mvc - ASP.Net MVC 应用程序注销未完全注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18280972/

相关文章:

c# - 实现 ITempDataProvider 与使用 Cookie

asp.net - 负载均衡器如何与 ASP.NET session 配合使用

amazon-web-services - 使用 AWS Cognito 保护 EC2 上托管的 Web 应用程序,而无需修改 Web 应用程序

javascript - 使用 put 或 delete(相对于 post)发送登录凭据是否安全?

asp.net-mvc - 如何通过 ASP.NET 发送多封电子邮件而不延迟响应

c# - 是否可以使用 SolrNet 映射复杂类型

php - PHP 7 中的 session

ruby-on-rails - 基本 Rails 问题 : Building Data Over Several Pages

java - 使用已配置的 JAAS 主题来验证 HttpURLConnection?

asp.net-mvc - Microsoft MVC 中的服务层和存储库设计