ASP.NET LoginStatus:注销无效

时间:2013-02-27 08:59:26

标签: c# asp.net .net authentication membership-provider

我正在使用成员资格提供程序开发一个Web应用程序,以实现对应用程序部分的身份验证和用户/角色访问。

我在我的母版页中使用LoginStatus控件作为注销链接,但测试它我发现注销不起作用。如果我再次尝试访问我的应用程序的任何页面(在登出后),页面会显示...

我认为这个问题取决于用户会话中存储的未自动清除的数据。那是对的吗?

那么实现注销和清除会话的核心方法是什么?

注意 我没有为LoginStatus控件实现任何事件。我正在使用表单身份验证。在我的登录页面中,我正在使用此代码:

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
   1, // Ticket version
   this.txtUser.Text, // Username associated with ticket
   DateTime.Now, // Date/time issued
   DateTime.Now.AddMinutes(30), // Date/time to expire
   true, // "true" for a persistent user cookie
   ruolo, // User-data, in this case the roles
   FormsAuthentication.FormsCookiePath);

string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
   FormsAuthentication.FormsCookieName,
   hash);

if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; }

Response.Cookies.Add(cookie);

在我的 web.config system.web部分中:

<authentication mode="Forms">
  <forms name=".ASPXAUTH" loginUrl="login.aspx" protection="All" path="/" domain="keyforup.it"/>
</authentication>
<authorization>
  <deny users="?"/>
</authorization>

2 个答案:

答案 0 :(得分:2)

我几乎失去了想法,试图找到解决这个问题的方法。一切在其他浏览器上工作正常,但firefox和chrome在登录后不会在初始页面上记录用户。

当我在site.master文件中将表单的action属性设置为action =“default.aspx”时,它开始工作。

当我查看资源管理器调试器时,表单操作具有默认值,但在chrome和firefox操作中没有设置属性。我认为这可能是.net登录状态控制脚本的问题。

由于我的系统现在正常工作,我不会进一步搜索,但我希望这对有类似问题的人有所帮助。

答案 1 :(得分:1)

Session.Abandon() LoggedOut控制事件中调用LoginStatus解决了这个问题,但我想知道这是否是达到此目的的最佳方法。