Expert Answer Center > Experts On Demand > View Answer
EMAIL THIS
Experts on Demand
  EXPERTS ON DEMAND HOME     POSE A QUESTION     VIEW ANSWERS     BROWSE BY TOPIC        RSS FEEDS  
How can I clear an application variable when the Web page is closed without a proper log out? I am designing a Web application using Visual Studio 2003, VB.NET and SQL 2000. I want to control unique logins of users by their user ID and password. I did this by assigning an application variable for the user ID and clearing this application variable at the logout.

However, when the Web page is closed without going through the logout, the application variable remains, and the user can't log in again. The only way out is to restart the computer.

I would appreciate it if you could show me a better way. QUESTION POSED ON: 15 APR 2005
QUESTION ANSWERED BY: Samuel Matzen I think you are on the right track, but the problem is how to keep the previous session from running when the user logs in again. You can do this by placing the sessionID in ApplicationState along with the userID.

When a page loads you can check to see if the SessionID is in ApplicationState, and if it is you know the user is logged in. If it isn't, you either have a defunct session or the user is not logged in. By placing the logged-in UserID in SessionState, you will be able to tell immediately if the user is logged in. If the UserID is in SessionState, look into ApplicationState for this UserID. If the UserID is not found in ApplicationState, the user is not logged in. If the UserID is found, check the SessionID of the current session against the SessionID in ApplicationState. If they are different, this session is defunct; if they are the same, then everything is OK.

After the login you can check the ApplicationState again and remove any previous login for the user before putting the current SessionID and UserID into ApplicationState.

The result is that the new session will override any previous session. When the user tries to run another page on the first session, a message will display that indicates the user has logged into a new session.

HomeExperts on DemandIT Expert Webcast SeriesExpert KnowledgebaseSite Index
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts