Use the Session_End () function in the global.asax file. See here for more details.
SO - end of session
EDIT: No, maybe it won't. See comments below.
If you need to redirect to the end of the session, can this do the trick for you?
private void Page_Load(object sender, System.EventArgs e) { Response.AddHeader("Refresh",Convert.ToString((Session.Timeout * 60) + 5)); if(Session["IsUserValid"].ToString()=="") Server.Transfer("Relogin.aspx"); }
EDIT 2: Caution, this can become tricky if you have AJAX material.
I have seen examples where people put this in the page_load of the base page and all your .aspx pages from that base page. This will not allow you to add this code for every single page that you have.
Why does the first method not work (Session_End)? This function is called internally on the server when the session ends. Thus, there is no associated request / response for redirection or transmission. Ie, this function can be called by the server 20 minutes after closing browswer.
Tommy source share