How can I force the Session_Start method on my global.asax to be called every time my application runs in development mode?
I have some code that I need to debug but sometimes it is called, sometimes it isn't. I already tried closing the "ASP.NET Development Server" but no luck.
Check out this article http://sandblogaspnet.blogspot.com/2008/03/methods-in-globalasax.html
Session start event is fired only when a new session for a user starts. Once “Session_Start” for a user is fired then if the user makes subsequent request to any resource within the application this event is not at all triggered. The event is triggered only when the user’s session expires and then the user tries to access any resource in the application again.
Are you sure you aren't looking for Application_Start? If not then as long as you reset the session that event should be called.
EDIT: Also check out this article on someone who was trying to do the same thing as you http://forums.asp.net/t/1608241.aspx/1
From that page:
You are right I just tested it by putting
<sessionState timeout="1"/>in my Web.config file. Then I waited 1 minute and clicked on a link on the page. It immediately went back into Session_Start and re-authenticated the user.
EDIT 2: Try calling Session.Abandon() from your start page. It should remove the session and require the user to start a new one.
I manage to do it by restarting the "ASP.NET State Service" which is the service used to manage session state on a computer.
Not the ideal solution but solves my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With