Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am using link button for log out option. The page will redirect to login page. After this browser back and forward buttons want to disable. Don't want to display the logged in page again.

"Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);"

I tried this code. But its not work. Can you please help me?

Thank you,
Regards,
Sangeetha
Posted

C#
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
        Response.AddHeader("pragma", "no-cache");
        Response.AddHeader("Cache-Control", "no-cache");
        Response.CacheControl = "no-cache";
        Response.Expires = -1;
        Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
        Response.Cache.SetNoStore();

         Page.ClientScript.RegisterStartupScript(this.GetType(), "cle", "windows.history.clear", true);

Or Use this JavaScript
C#
<script> 
function noBack(){window.history.forward();}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack();}
window.onunload=function(){void(0);}
</script>

Check for more information
 
Share this answer
 
v4
 
Share this answer
 
v2
Use
C#
History.Forward()
in the Log out event.
 
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