如何仅从登录页面禁用我的mvc中的浏览器后退按钮? [英] How to disable the browser back button in my mvc from only my login page?
问题描述
我尝试了此方法放在我的login.cshtml中,但根本不起作用.然后,我尝试将其放入我的_Layout.cshtml中,但是这样做确实可以在影响整个网站的同时(如预期的那样).关于我应该放在哪里或应该如何操作代码的任何提示?
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 entire website (as expected). Any tips on where I should put or how I should manipulate the code?
在这里:
function preventBack() { window.history.forward(); }
setTimeout("preventBack()", 0);
推荐答案
我最近在MVC项目中使用了它.也许您可以将其放在登录重定向到的页面上.
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 functionality
function noBack() { window.history.forward() }
noBack();
window.onload = noBack;
window.onpageshow = function(evt) { if (evt.persisted) noBack() }
window.onunload = function() { void (0) }
如果出于安全原因使用它,请务必小心,因为Javascript不是处理站点内安全逻辑的最理想解决方案.由于Javascript代码是在客户端PC上执行的,并且/或者可以被浏览器禁用,因此很容易解决.
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.
这篇关于如何仅从登录页面禁用我的mvc中的浏览器后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!