Saturday, March 24, 2012

Ajax Timer and Session Timeout

I want to detect a page with ajax timer to check if the session is timeout. however, the timer will keep the session always ON.
Thus i write a counter to check the session. However the Session variable will be always = 5.
Why ? or is there any other methods to check if the sesison is timout ?

Thanks.

protected

void Page_Load(object sender,EventArgs e)
{
Session.Add("CheckSession", 5);
}protectedvoid Timer1_Tick(object sender,EventArgs e)
{
int j = (int)Session["CheckSession"] - 1;
if (j <= 0)
{
this.Response.Redirect(http://www.google.com);
}
Session["CheckSession"] = j;
}

In page load check for post back.

ie. Session.add cod shouldgo into following block. Currently for each time tick event is calledpag_load also is getting executed and checkSession remains as 5 always.

if(!Page.IsPostBack()){

}

No comments:

Post a Comment