IrfanRaza
IrfanRaza

Reputation: 3058

Session not ending in ASP.NET

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.

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.

Upvotes: 0

Views: 401

Answers (2)

Dante
Dante

Reputation: 3891

You cannot make the class static. Worse than keeping the user logged in across sessions is the fact you cannot have multiple users in your system. They will all share the same login information. You should read about static.

What you want is to store an instance of that class in the session and access it whenever you need.

Upvotes: 0

Tim Greaves
Tim Greaves

Reputation: 755

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.

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.

So something like:

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

Upvotes: 1

Related Questions