问题描述
我已使用以下代码设置HTTP标头 Pragma:无缓存和 Cache-Control:无缓存,无控制
I have used following code to set HTTP header Pragma : no-cache And Cache-Control : no-cache, no-control
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
我检查了响应头是否包含Pragma:无高速缓存意味着上面的C#代码可以正常工作.
I checked response header contains Pragma: no-cache that means above C# code is working fine.
我的问题是
应用程序响应标头包含Pragma:no-cache和Cache-Control:no-chase.那为什么要浏览保存历史记录呢?
Application response header contains Pragma: no-cache and Cache-Control: no-chase. Then why browse saving the history?
我需要帮助,如何通过浏览器禁用后退按钮或保存历史记录.
I need help how I can disable back button or saving history by browser.
我知道我可以通过js在浏览器中隐藏工具栏,还可以通过编写js代码来禁用后退按钮功能,但是我需要另一种解决方案.
I know I can hide tool bar from browser by js and also can disable back button functionality by writing js code but I need another solution.
等待您的帮助.
推荐答案
缓存与历史记录无关.这是两个不同的功能.禁用缓存不会指示浏览器避免保存历史记录.没有支持禁用后退按钮"或禁用历史记录的方法.
Cache has nothing to do with history. These are two different functions. Disabling cacheing does not instruct the browser to avoid saving history. There is no supported way to "disable the back button" or disable history.
这是一个客户端功能.可能有或可能没有某些特定于浏览器的黑客,但是这些黑客不受支持,并且可能会随着浏览器,移动浏览器等较新版本的破解而消失.
This is a client feature. There may or may not be certain browser specific hacks you could do, but these are unsupported and will likely break with newer versions of browsers, mobile browsers, etc...
设计您的网站,而不是试图强迫浏览器执行原本不是设计的操作,请设计您的网站,以使后退"按钮不会引起问题.
Instead of trying to force the browser to do something it wasn't designed to do, design your site so the back button doesn't cause problems.
例如,使用发布重定向获取"模式可以帮助减轻数据的重新发布.
For instance, use the Post Redirect Get pattern to help mitigate reposting data.
我拒绝使用任何以此方式干扰我的浏览器的网站(我可能想保留其他历史记录,如果您未经我的许可将其删除,我会非常生气).我知道其他许多人也有同样的感觉.因此,除非您想疏远用户,否则不要这样做.
I refuse to use any site that messes with my browser in this manner (I may have other history that I want to keep, and if you go deleting it on me without my permission, I will be very angry). I know many other people that feel the same. So unless you want to alienate your users, don't do it.
这篇关于如何从ASP.net MVC禁用浏览器历史记录保存或兑现选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!