0

I am building an application in MasterPage. Now I have an Login page from which my user is redirected to the masterpage when he is loging in. For authentication I am using FormsAuthentication and it works fine.

Now when the user is on the MaseterPage I have a logout button. If i click on that button I will be redirected to my LoginPage, but if I click on the back button in the browser , the last page before clicking 'Logout' is rendered again.,,,how to avoid it....
(iam using ASP.NET and C#)

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by miraclebos
0

Add the following code to your Home (Masterpage as you call it).
In the Page_Load event:

Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
Response.Expires = -1500;
Response.CacheControl = "no-cache";
if (Session["username"] == "xx")
{
Response.Redirect("Login.aspx");
}
else
{
Label1.Text = "Welcome " + Session["username"] + "!";


}

And in the Logout eventhandler add:

{
Session["username"] = "xx";
Response.Redirect("Login.aspx");


}

Should work perfectly!
Explanation: Disabled back button by disabling cache for the page..
Used session variable to check if logged in or not..

Edited by happygeek: fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.