[英]How to redirect the page quickly when the user clicks the browser back button in asp.net
I am building an application as server client concept, in which the server is an asp.net application. 我正在将应用程序构建为服务器客户端概念,其中服务器是asp.net应用程序。 What i am trying to do is
我想做的是
May i know the reason, when the browser back button is click whether the page load event will be fired or what is the process going on behind the screens.How can i make the page to redirect quickly. 我是否可以知道原因,当单击浏览器的后退按钮时,是否将触发页面加载事件,或者屏幕背后的进程是什么?如何使页面快速重定向。
Also i surfed the net and found that to avoid caching the page, i have added in all pages and master page, but no use of it. 我也上网冲浪,发现为了避免缓存页面,我在所有页面和母版页中添加了内容,但没有使用它。 It remains the same.
它保持不变。
就像您说的那样,您需要通过设置cache-control: no-cache
标头来确保不缓存上一页,您可以在ASP.NET中使用以下命令执行此操作:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Actually browser caching is difficult with all browsers. 实际上,所有浏览器都很难进行浏览器缓存。 You cant even be 100% certain its not being cached even if you do this (browsers do things on their own regardless of what you tell them, but this should cover most bases):
即使执行此操作,您也不能100%地确定它不会被缓存(浏览器会自己处理,而不管您告诉他们什么,但这应该涵盖大多数基础):
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
Response.Expires = -1500;
Response.CacheControl = "no-cache";
Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Now also dont think that is enough. 现在也不要认为那是足够的。 Firefox likes to cache with Url's, so if you ever link to a page you might need to change the URL by adding a timestamp to the end of it.
Firefox喜欢使用Url进行缓存,因此,如果您链接到页面,则可能需要通过在其末尾添加时间戳来更改URL。
However if it isnt the cache that is causing the issue, then you can do some server side logic. 但是,如果不是引起问题的缓存,则可以执行一些服务器端逻辑。 Such as if the session doesnt exist in the codebehind, redirect in the code behind, this will redirect before any page is loaded.
例如,如果会话在后面的代码中不存在,则在后面的代码中重定向,这将在加载任何页面之前重定向。 If the page does still load after this, then it is certainly a browser caching issue.
如果此后页面仍然加载,则肯定是浏览器缓存问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.