简体   繁体   English

当用户单击asp.net中的浏览器后退按钮时,如何快速重定向页面

[英]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 我想做的是

  1. User enter the link and provide the login details in the login page. 用户输入链接并在登录页面中提供登录详细信息。
  2. After authentication the user will be redirected to the main page, which is a master and child page. 身份验证后,用户将被重定向到主页,即主页和子页面。
  3. Now when i click the sign out button (which is available in master page) the sessions are cleared and redirected back to the login page.this is fine. 现在,当我单击``退出''按钮(在主页上可用)时,会话将被清除并重定向回登录页面。
  4. But, When i try to click the back button in browser, i have been made to see the previous page and after few seconds i have been redirected back to the login page. 但是,当我尝试单击浏览器中的“后退”按钮时,我已经看到了上一页,几秒钟后我被重定向回登录页面。

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.

相关问题 注销后,如何在ASP.NET MVC3中单击浏览器的后退按钮时将用户重定向到登录页面 - After logout,how to redirect user to login page when he/she will click back button of browser in ASP.NET MVC3 如果用户单击asp.net中的浏览器“后退”按钮,如何清除/放弃会话 - How to clear / abandon Session if user clicks on browser Back button in asp.net 用户单击浏览器停止按钮时如何停止服务器端处理(ASP.net C#) - How to stop server side processing when user clicks browser stop button (ASP.net C#) 超时后,如何将用户重定向回退出页面? Asp.net MVC - How can I redirect a user back to signout page when timed out? Asp.net MVC 当用户在 asp.net c# 中注销时如何禁用浏览器中的后退按钮 - How to disable the back button in browser when user logout in asp.net c# 单击asp.net中的浏览器的后退按钮时,需要重定向到登录页面 - Need to redirect to Login page on clicking browser's back button in asp.net 使用浏览器后退按钮加载ASP.NET页面 - ASP.NET Page loading with browser back button 单击浏览器上的“后退”按钮时的Asp.Net Force Page_Load - Asp.Net Force Page_Load when Clicking Back Button On Browser 如果用户使用ASP.NET直接在浏览器中输入URL,如何重定向到登录页面 - how to redirect to login page if user directly entres URL in browser using ASP.NET 当用户单击未设置缓存的返回按钮时,防止 ASP.NET Webforms 中的页面过期消息 - Prevent page expired message in ASP.NET Webforms when user click back button with no-cache set
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM