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#)

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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.