Faqs on asp.net,c#,vb.net and sqlserver2005

this blog covers all the Faqs related to .net technologies like asp.net,vb.net,c#.net,ajax,javascript and sqlserver2005.

Mar 11, 2008

How to expire a web page immediately?

If user clicked Sign Out, the session is abandon and the browser diaplays the login screen. If the user clicks the browser Back button, the previous page should not come back. How does it work?

You need to set the page to not cache and check if the session exists on page load and redirect to the login page if it doesn't. Something like:

protected void Page_Load(object sender, EventArgs e)
{
SessionCheck();
Cache.SetCacheability(HttpCacheability.NoCache);
}
private void SessionCheck()
{
if (Session.Count == 0)
{
Response.Redirect("~/login.aspx");
}
}

Happy Programming

0 Comments:

Post a Comment

<< Home