I want to sign out a user when his session times out. So used following code in Global.asax:
protected void Session_End(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
}
But seems session_end
never fires. Any idea how can fix it? I'm using ASP.NET with default settings.
Are you sure that it never fires ?
As I understand it
Session_End
has nothing to do with the current request because ASP.NET session is terminated by the timeout AFTER the last request from the client has arrived. The call toFormsAuthenticaion.SignOut
manipulates authentication cookies and therefore has no effect without any connectivity from the client (browser).Take a look at this question (which has an answer) - the problem is more or less similar to yours so you might find a right solution:
Session_End in Global.asax.cs not firing using forms authentication
Hope this helps.
You may set some Session data in Session_Start. Without this, Session_End will not be fired. see this
I don't know if it is a feature or bug. Or may be I don't understand enough session managment in ASP.NET. But this is what I found.
Session_End does not fire in ASP.NET MVC 4 (with default settings for sessionState element in web.config) if Session_Start is not declared.
So you need declare Session_Start to catch Session_End :)
In your web.config you need to have the sessionState element as a child of the element
I dont know how its working, but it will fire when i close my browser after time out period.
Call this from