menu

Tuesday, June 22, 2010

How to check if a particular session is alive

Suppose we have a login page and a home page, if login is success redirect to home page. And if session is expire on home page it again redirects to login page.

code in login.aspx.cs page

protected void Page_Load(object sender, EventArgs e)
{
Session["sessionid"] = Session.SessionID;
}

code in web.config file

--
--
--
--

where timeout="20" is in minutes.

code in home.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
if (Session["sessionid"]==null)
{
Response.Redirect("login.aspx");
}
}


No comments:

Post a Comment