Click here to Skip to main content
16,004,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Expert,

In asp.net website i have use masterpage where i put one button for logout option.

On master page load event i write following code for button text(login or logout).

if (Session["session_log_id"] == null)
        {
            lblUserName.Text = "";
            buttLogin.Text = "Login";
        }
        else
        {
            lblUserName.Text = "<font color=#666666 size=2 face=Arial, Helvetica, sans-serif>Hi </font> , <font color=#822228 size=2 face=Arial, Helvetica, sans-serif>" + Session["session_logged_username"].ToString() + "</font>";
            buttLogin.Text = "Logout";
        }

On that buttons onclick event,i write code
Session.RemoveAll()


and redirect the user to Home page.

Upto this working fine for me.But after that when i hit back button it return to that page and show logout button again.

on each page load event i have write code like this to check wheather session is exist or not and prevent the unlogged user.

if (Session["session_log_id"] == null)
        {
            lblUserName.Text = "";
            buttLogin.Text = "Login";
        }
        else
        {
            lblUserName.Text = "<font color=#666666 size=2 face=Arial, Helvetica, sans-serif>Hi </font> , <font color=#822228 size=2 face=Arial, Helvetica, sans-serif>" + Session["session_logged_username"].ToString() + "</font>";
            buttLogin.Text = "Logout";
        }


How to clear session completely , so user can not return back after logout?


Thanks in advance......
Posted

 
Share this answer
 
Comments
Espen Harlinn 20-Oct-11 5:20am    
Right :)
be friendly with google , use it frequently ,
for ur solution sake try by using Session.Abondon
 
Share this answer
 
The question has been asked many a times. We have an article (or tip/trick) explaining how this can be taken care of. The key thing here is disabling cache.
Here is the Google search link - logout back button asp net[^]. Start typing and Google will suggest you too to make your search even easier.
You may also use Code Project search to find the similar questions and articles.
 
Share this answer
 
Instead of Session.RemoveAll() you have to use Session.Abandon() and check the below link.

Browser back button issue after logout[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900