Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey there.
So I have the following scenario:
Everytime a user logs in I write into a table with a field that displays whether there is an active session or not. When the user disconnects, it sets the field so that it says that the user is disconnected an the session is invalid. Now here's the obvious problem. When I shut the site down, the fields wont be set to invalid and on the next startup of the site, there are a bunch of invalid sessions. I could set them all to invalid manually but that's a rather sloppy solution. I was wondering if there's any mechanism I could use to set the fields initially to invalid on start of the asp.net site?

Thanks in advance.
Dennis
Posted
Comments
PIEBALDconsult 4-Apr-15 12:34pm    
What can the site do when you ask it to shut down?
Dennis Baberich 4-Apr-15 12:39pm    
Doing something on shutdown is not a possible option. I want to make sure that if the server crashes ( just as an example ) everything will run well on next startup. Therefore I need to clean the tables on startup.

1 solution

Use Aplication_start event from the global.asax file. You can write your custom logic here to cleanup the invalid sessions. This is the first event to called every time application starts.
 
Share this answer
 
Comments
Dennis Baberich 4-Apr-15 13:08pm    
Perfect. I did not have the file but had no hassle adding it myself. Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900