Sample code for LOGOUT in asp.net 2.0?

Here is the small code to do LOGOUT in asp.net 2.0

protected void lnkbtnLogout_Click(object sender, EventArgs e)

{

try

{

FormsAuthentication.SignOut();

Session.Abandon();

Response.Cache.SetCacheability(HttpCacheability.Private);

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Redirect("~/Login.aspx");

}

catch (Exception ex)

{



throw ex;

}



}

3 comments:

sinhong said...

hi, i followed ur code but when i click the back button from browser, it still showing the previous page.

How to do so that can prevent this to happen?

thx you

Robin Thomas said...

You have to care about the browser back button problem after logout. Other wise user will be able to go back and see the content of the previous page by clicking browser back button.. see the following post

Disabling browser back button after signout

Tech Shankar said...

Thanks to : sinhong & Robin Thomas