1

Whenever I click on logout button it Redirect me to login page but when im clicking on back button it redirect me to last visited page. I am not using membership or Windows Authentication.

Session.Abandon();
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Redirect("LoginForm.aspx");
Sukrit Kalra
  • 33,167
  • 7
  • 69
  • 71

5 Answers5

1

If you are using session then destroy the session value on logout button click and you can put the check like this in your app webpages

if(Session["sessionvaribale"].Equals(null))
{
Response.Redirect("logoutpage url");
}
0

what kind of authentication do you use then?

In c# the code for logging out with forms authentication would be:

// body of function
FormsAuthentication.SignOut();
HttpContext.Current.Response.Redirect("Login.aspx", true);
0

One of the reason is the page is being cached by browser and load the from there. In case you do not want in any case to see any page after logout , use the no-cache for all the pages

Devesh
  • 4,500
  • 1
  • 17
  • 28
0

If you're using FormsAuthentication, you might want to signout using its method too.

Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect("index.aspx");

Clearing cache doesn't work in all browser and I found in my experiments that user can go back to previous page after loging out. Hence you may want to use JavaScript to prevent user going back, once he logs out.

Below article outlines the same thing:

http://www.aspsnippets.com/Blue/Articles/Disable-Browser-Back-Button-Functionality-using-JavaScript.aspx

It works cross browser.

Apart from that you may want to check below post, that works too:

https://stackoverflow.com/a/5881175/309395

Community
  • 1
  • 1
Nilesh Thakkar
  • 2,877
  • 1
  • 24
  • 43
0

on logout click first make the session null

Session.Abandon();
 Session.RemoveAll()
Session.Clear();

any one

then after if you are using master page, that is better in case of multiple page,

just check on masterpage load event if session is null then move to login page

if you are not using master page then check if session is null for each page

Md. Parvez Alam
  • 4,326
  • 5
  • 48
  • 108