Monday, January 2, 2012

Automatic Timeout in Session

To Implement auto redirection after session expires....
do the following:

Write this code in to the masterpage's cs file

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
this.HeadContent.Controls.Add(new LiteralControl(
String.Format("",
SessionTimeOutWithin * 60, PageToSentAfterSessionTimeOut)));
}


Now also add below methods in masterpage...

public string PageToSentAfterSessionTimeOut
{
get { return "CheckSessionTimeOut.aspx"; }
}

public int SessionTimeOutWithin
{
get { return Session.Timeout; }
}

Now in WebConfig set the timeout.
Here I have set timeout to 1 minute for checking purpose....
please change it as per your requirement.

sessionState mode="InProc" cookieless="true" timeout="1">

No comments:

Post a Comment