Search code examples
c#javascriptasp.netbrowserback

How to alter browser's back button functionality similar to eCommerce sites in asp.net


I have a web application, in which browser's back button functionality should be customized. It's like, whenever we click on browser's back button, it should take us to landing page(Login page), It should display error message saying that 'session expired. Please login again'.

I have gone through so many posts and even in stack overflow also, i saw few posts. But nothing worked for me. The java script approach i am using as a temporary workaround.Basically this JavaScript never allow us to go back. instead it will keep us in same page. JavaScript i have used <script>history.go(1)</script>

Please help me to customize the functionality of Browser's back button. Any suggestions will be really helpful to me.


Solution

  • Short answer: You cannot
    A little longer: You shouldn't even try.

    But if you insist: A Thorough Examination of "Disabling the Back Button." (from 2000, but since it is ASP I guess still valid for you :)

    Newer dot net: Restrict user go back to previous page after signout

    Ignore the older browsers do not support location.replace - IE3.2 is not considered older any more but ancient.