Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
i want to disable back button of browser after logout but when i login it goes a to b page now i logout from b page then a page comes if i click on back button of a page then i want to disable plz help me?
Posted

You can't disable the back button. Nor should you be able to.

But you can stop the back button loading the page from memory/cache.

You need to set some response headers when you originally serve the page.

C#
response.headers["Cache-Control"] = "private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"


Then when the user clicks back, it will request the page again from the server and you can redirect back to the login page.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Jun-13 9:22am    
Just a note: when you disable cache, you can effectively, indirectly disable the back button.
—SA
Get many similar threads on CP Search[^]
 
Share this answer
 
Comments
Keith Barrow 19-Jun-13 16:39pm    
Hi, I've left a comment on Mohammed Mitwalli's answer, it applies here, normally I'd retype, but I'm on my mobile.
Not only should you not disable the back button (this is bad for usability) you can't disable the back button reliably across all versions of all browsers.
You need to fix the underlying problem, which is the browser displaying the cached version of the page. This article : "Browser back button issue after logout[^]" presents some options. You also need to make sure that you have "properly" logged the user out (i.e. they cannot access the page when they have been logged out - you aren't just relying on them not accessing the URL), but that is a separate issue and should not be a problem if you've implemented things well.
 
Share this answer
 
Hi ,
Check this link
disable browser back button in asp.net(c#)[^]
Best Regards
M.Mitwalli
 
Share this answer
 
Comments
Keith Barrow 19-Jun-13 16:32pm    
Hi, I've yet to see a back button properly disabled across all browsers and versions. Not only that, I'd say it is "bad manners" to try to disable GUI functionality from a website.. Furthermore, I've seen a few sites where disabling the back button just tries to hide poor security. The answer is to disable the cache on secured pages, if the user presses back this forces a re-load, and if the security is properly written, the user will be re-directed to login or wherever. This does nit interference with the browser itself.

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