会话未在 ASP.NET 中结束 [英] Session not ending in ASP.NET

查看:46
本文介绍了会话未在 ASP.NET 中结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用 global.asax 的 asp.net 应用程序.我创建了一个静态类,它使用属性存储用户信息,例如 LoginID、CompanyID 等.IsLoggedIn 属性指示用户是否登录.我在同一个类中创建了一个方法 ResetAll() 来重置这些属性.

I have created an asp.net application in which i have used global.asax. I have created a static class which stores user information such as LoginID, CompanyID etc using properties. A property IsLoggedIn indicates whether user logged in or not. I have created a method ResetAll() within the same class to reset those properties.

问题在于,如果用户没有注销就直接关闭浏览器窗口,则不会重置属性值.因此,如果用户打开一个新的浏览器窗口,用户将自动登录.我还在 Session_End() 中调用了 ResetAll() 但它仍然无法正常工作.有人能解释一下这有什么问题吗,或者如果用户直接关闭浏览器窗口,如何重置属性值.

The problem is that if the user directly closes the browser window without logging off the property values are not resetted. Therefore if the user opens a new browser window, the user is logged in automatically. I have also called ResetAll() within from Session_End() but still it is not working. Could someone explain me whats wrong with that or simply how to reset the property values if the user directly closes the browser window.

推荐答案

如果我没看错,并且您有一个包含静态成员的类,那么您将遇到问题.对于 ASP.NET Web 应用,静态成员对于整个 AppDomain 是静态的,而不仅仅是对于单个用户,因此无论请求来自何处,这些值都是相同的.

If I am reading this correctly and you have a class with static members, then you are going to run into issues. With an ASP.NET web app, static members are static for the entire AppDomain, not just for an individual user, so the values would be the same no matter where the request has come from.

听起来您真正需要考虑的是在会话中存储用户信息类的实例.这样,信息就特定于该特定用户.此外,这应该可以解决您的问题,因为通常会在浏览器窗口关闭时删除会话 cookie,从而在浏览器窗口重新打开时强制进行新会话.

It sounds like what you really need to think about doing is storing an instance of the user information class in the session. That way the information is specific to that particular user. Also, that should solve your issue as the session cookie is normally removed when the browser window is closed, forcing a new session when the browser window is re-opened.

比如:

Dim thisUser As New UserInformation()
thisUser.LoginID = someValue
Session("UserInformation") = thisUser

这篇关于会话未在 ASP.NET 中结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆