ASP.Net logout code block

JPJedi picture JPJedi · Jun 11, 2009 · Viewed 12.2k times · Source

I need a good logout code block for asp.net. Currently after you logout you can hit the back button and continue using the site.

Answer

Jose Basilio picture Jose Basilio · Jun 11, 2009

You need to make sure that the session is abandoned and call the FormsAuthentication.SignOut() method as shown below:

private void Logout()
{
  Session.Abandon();
  FormsAuthentication.SignOut();
  FormsAuthentication.RedirectToLoginPage();
}