Control of forward and backward button of browser
I hav开发者_如何转开发e a login page and once a person is logged in , he should not be allowed to move back to login page.
So , can someone tell me how to disable backward/forward button of browser ?As everyone else mentions, not only can you not disable the back button but that is the wrong solution to your problem. So long as you are using standard .net user authentication mechanisms you can put the following in the code behind of your login page:
if (User.Identity.IsAuthenticated)
{
//Code to redirect to some other page
}
No, you can't (and shouldn't) disable the backward or forward buttons of the the browser. Why can't the user go back to the login page?
The trick to understanding this is to understand that it's the user's browser, not yours. You don't get to control anything your page didn't render.
It is impossible to disable the back button of a user's browser.
Disabling the back button (even if it were possible) wouldn't stop the user getting to the login page. They could simply type in the URL again, or fetch it from a bookmark.
If your goal is to prevent the login page being shown once the user is already logged in, you will need to handle this yourself when serving the login page: check if the user is already logged in and simply serve up different content. At the simplest - a "Logged in as " message instead of the login form. Alternatively, do a server-side redirect to the user's home page, or some other useful page on your site.
精彩评论