Skip to content Skip to sidebar Skip to footer

How To Disable The Browser Back Button In My Mvc From Only My Login Page?

I tried this method by putting it in my login.cshtml but it doesnt work there at all. Then I tried putting it in my _Layout.cshtml but then it does it's job while affecting the ent

Solution 1:

I recently used this in an MVC project. Maybe you can put it on the page that the login redirects to.

//kill all back button functionalityfunctionnoBack() { window.history.forward() }
noBack();
window.onload = noBack;
window.onpageshow = function(evt) { if (evt.persisted) noBack() }
window.onunload = function() { void (0) }

Do be careful though if you are using this for security reasons, as Javascript is not the most ideal solution to handle secure logic within a site. It is easy to get around since the Javascript code is executed on the clients PC and/or it can be disabled by the browser.

Solution 2:

You can put it in the layout but active it only if your on the login page :

if(window.location.href.toLowerCase().indexOf("login") > -1)
 {
     function preventBack() { window.history.forward(); }
     setTimeout("preventBack()", 0);
 }

Post a Comment for "How To Disable The Browser Back Button In My Mvc From Only My Login Page?"