Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In homepage when I click on logout its goes to login page button. But when I clicked back button of the browser it directly go to Home page. How to handle this type of error in asp.net, C#.net?

Do we need to write any code in Global.asax?

Someone please help me.
Posted
Updated 8-Nov-10 18:37pm
v2

window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{
case 116 : // F5;
event.returnValue = false;
event.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
 
Share this answer
 
If you are using forms authentication.

// Page load event of Logout.aspx
FormsAuthentication.SignOut();
Response.Redirect("Default.aspx");

//Session
//in your Global.asax file
void Session_Start(object sender, EventArgs e)
  {
    // Code that runs when a new session is started
      if (Session["UserID"] == null)
      {
          Response.Redirect("Login.aspx");
      }
 
Share this answer
 
XML
no need to write any code in Global.asax file....
Use javascript to disable the back button....
<a href="http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm">http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm</a>[<a href="http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm" target="_blank" title="New Window">^</a>]
 
Share this answer
 
Comments
venkatrao palepu 9-Nov-10 0:52am    
Hi senguptaamlan

your code is working fine...

But i want code without disable backbutton. what code we write in Global.asax
use.. to avoid back button

C#
protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        string strDisAbleBackButton;
        strDisAbleBackButton = "<script language='javascript'>\n";
        strDisAbleBackButton += "window.history.forward(1);\n";
        strDisAbleBackButton += "\n</script>";
        ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "clientScript", strDisAbleBackButton);
    }
 
Share this answer
 
Comments
venkatrao palepu 9-Nov-10 0:52am    
Hi Suthish

your code is working fine...

But i want code without disable backbutton. what code we write in Global.asax

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