Click here to Skip to main content
16,012,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actaully I have created a logout page. When I click on logout button it redirects me to login page...but as a press back button of browser it reopen welcome page. I want to do that if any user click on log out button and after that press back button it should not open welcome page.


Coding is as follows on welcome page:-

C#
public partial class Home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        if (!IsPostBack)
        {
            Label1.Text = (string)Session["username"];   
        }
        
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        Session.Remove("username");
        FormsAuthentication.SignOut();
        
        Response.Redirect("Default.aspx");

    }
}
Posted
Updated 13-Aug-13 0:43am
v2
Comments
VICK 13-Aug-13 6:39am    
Dont you think that You should abandon the session after removing the session.. as I think you are abandoning the session first and not removing the username from there.. so when you went to the back page username still persist there...
rranjansir 13-Aug-13 6:47am    
actually user name is not showing.....but the page contents are showing on back button
VICK 13-Aug-13 6:50am    
Ok.. than try to use only these two lines.


session.abandon();
Response.Redirect("Default.aspx");
rranjansir 13-Aug-13 6:55am    
its nt wrkng...same prblm
VICK 13-Aug-13 7:08am    
Well, when the previous page opened than does still the options work on that page.. for example after signing out when you push back button than does nay button or link works on that page???

you just need to remove all the sessions that you've already created.
whenever after redirecting your desired page check whether sessions will have nothing as their values in them.
After doing so, the page you get on click event of back button just check whether their are active sessions, if they are not having any values redirect to the login page.

thanks..
 
Share this answer
 
Comments
rranjansir 13-Aug-13 7:02am    
Read Question Carefully...m askin abt when click on back button it shows me welcome page
salah9 13-Aug-13 7:26am    
When user is on logout page, dont allow him to go to back page...
If you try to permanent solution for all pages then try as below:
First make one base page and override OnPreInit event and in them check session as you use and if session is not available or have not value then redirect to login page for access welcome or any other page as you required.

This base page inherits to any page as you required to login successfully.
 
Share this answer
 
Do you try this solution?
Browser Back Button Issue After Logout[^]
Or,see..
Browser Back button Issue[^]

Solution to back button problem after logout in ASP.NET
[^]
Or, have a search in CodeProject[^] for this issue,tons of helpful links there.
 
Share this answer
 
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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