简体   繁体   English

ASP.NET LoginStatus:注销无效

[英]ASP.NET LoginStatus: logout not working

I'm working on a web-app using Membership Provider to implement authentication and user/role access to application sections. 我正在使用成员资格提供程序开发一个Web应用程序,以实现对应用程序部分的身份验证和用户/角色访问。

I'm using LoginStatus control in my master page as logout link, but testing it I discovered that logout doesn't work. 我在我的母版页中使用LoginStatus控件作为注销链接,但测试它我发现注销不起作用。 If I try to access again to any page of my application (after loggin-out) the page is shown... 如果我再次尝试访问我的应用程序的任何页面(登出后),将显示该页面...

I suppose this problem depends on data stored in user session that isn't cleared automatically. 我想这个问题取决于存储在用户会话中的数据不会自动清除。 That's right? 那就对了?

So which is the corect way to implement logout and clear session? 那么实现注销和清除会话的核心方法是什么?

NOTE I'm not implementing any event for the LoginStatus control. 注意我没有为LoginStatus控件实现任何事件。 I'm using Form authentication. 我正在使用表单身份验证。 In my login page I'm using this code: 在我的登录页面中,我正在使用此代码:

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);

In my web.config system.web section: 在我的web.config system.web部分:

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

I almost lost my mind trying to find a solution to this problem. 我几乎想不起来试图找到解决这个问题的方法。 Everything Works fine on other browsers but the firefox and chrome does not log the user out on the initial page after login. 一切在其他浏览器上工作正常,但firefox和chrome在登录后不会在初始页面上记录用户。

When I set the action property of the form in the site.master file as action="default.aspx" it started to work. 当我在site.master文件中将表单的action属性设置为action =“default.aspx”时,它开始工作。

When I looked in the explorer debugger the form action had the default value but on chrome and firefox action had not property set. 当我查看资源管理器调试器时,表单操作具有默认值,但在chrome和firefox操作中没有设置属性。 I am thinking that this might be a problem with the .net login status controls scripts. 我认为这可能是.net登录状态控制脚本的问题。

Since my system now Works I wont search further but I hope this will be helpfull to someone having similar problem. 由于我的系统现在工作,我不会进一步搜索,但我希望这对有类似问题的人有帮助。

调用Session.Abandon()LoggedOut事件LoginStatus控制解决这个问题,但我不知道这是否是实现这一目标的最佳途径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM