how to redirect the page when Session Expires?
I read this on http://forums.asp.net/t/1137344.aspx
when I was modifying a Global.asax file that had Response.Redirect written in its Session_End Event. I guess the programmer aimed to redirect the application to the error page like this but the fact is that u dont have the Response Object in this particular event, the reason being that it’s fired internally by the server when the session gets expired. As an alternate to that I read this post post on the above mentioned URL, it suggests that we should use a BasePage and add this code in its PageLoad event. This way the meta info will be added to all the pages that inherit from this BasePage and they will redirect after 5 seconds of the Session timeout.
I think its quite brilliant, so hats off to ya!
HI, anilperugu: The easiest way what I feel is to use Meta information and get the trick working. Consider we have a page WebPage.aspx add the below code in the the WebPage.aspx.cs file.
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”);
}
In the above code, The WebPage.aspx is refreshed after 5 seconds once the Session is expired. And in the page load the session is validated, as the session is no more valid. The page is redirected to the Re-Login page. Every post-back to the server will refresh the session and the same will be updated in the Meta information of the WebPage.aspx.
Best Regards,
Sincerely,
Rex Lin
Microsoft Online Community Support

