Click here to Skip to main content
15,867,956 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am a fresher. I am trying to developed a ASP.NET web site but I am not able to do proper logout.
When I logout our page then it go to logout but I click on back button of browser then again open previous page
So plz any body help me.
My written code below.

I use this code on login.cs
C#
try
{
    if (dt.Rows.Count > 0)
    {
        Session["Login"] = true;
        Session["UserName"] = dt.Rows[0]["UserName"].ToString();
       username = dt.Rows[0]["UserName"].ToString();
    }
    else
    {
        Response.Write("<Script>alert('data is not match');window.location.href='stafflogin.aspx';</Script>");
    }
}
catch
{
}
finally
{
response.Redirect("Default.aspx");
}

and logout page
C#
protected void logout_Click(object sender, EventArgs e)
{
    Session["Login"] = false;
    Session.RemoveAll();
    Response.Redirect("~/stafflogin.aspx");
}
Posted
v4
Comments
Ankur\m/ 15-Apr-14 3:29am    
This is a very common issue. Google it and you will found millions of posts talking about it (keywords - logout back button asp.net). Please do search before you ask.

1 solution

Frequent Question in CodeProject

Refer:
Browser Back Button Issue After Logout[^]
Browser back button issue after logout[^]

and more here[^]
 
Share this answer
 

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