页面重新加载/重定向问题

人气:960 发布:2022-09-22 标签: jquery javascript asp.net ASP.NET

问题描述

H ello guys, 我在我的页面中使用以下脚本

 <   script  >   $(文档).ready(function(){ debugger;  var checkId = document.getElementById(RedirectWindow);  if(checkId!= undefined){ setInterval(function( ){ window.location.href =@ Url.Action(Index,Dashboard); },2000); } });  <   / script  >  

下面是渲染div的条件

 @ { if(ViewBag.SuccessMessage!= null) { <   div     id   =  removeDiv >   <  < span class =code-leadattribute> div     style   = 颜色:绿色    id   =  RedirectWindow  >   <  标签 > 配置文件已成功更新... <   / label  >   <   / div  >   <   / div  >  } } 

现在我在这里做第一次我在 viewbag 的基础上传递一些值我将成功消息呈现给最终用户并等待2秒后用户重定向到另一个页面 该页面名称为个人资料,如果用户点击了个人资料,重定向的页面现在是仪表板中的仪表板链接它回到这个页面和condtional div没有reneder。 一切顺利到这里!!! 如果我点击浏览器返回按钮它转到配置文件页面那里它检查div是否存在它在那里找到它并再次被重定向到仪表板页面 我想如果用户通过点击浏览器后退按钮而不是页面返回来自缓存。

解决方案

(document).ready(function(){ debugger; var checkId = document.getElementById(RedirectWindow); if(checkId!= undefined){ setInterval(function(){ window.location.href =@ Url.Action(Index,Dashboard); },2000); } }); < / script >

下面是渲染div的条件

 @ { if(ViewBag.SuccessMessage!= null) { <   div     id   =  removeDiv >   <  < span class =code-leadattribute> div     style   = 颜色:绿色    id   =  RedirectWindow  >   <  标签 > 配置文件已成功更新... <   / label  >   <   / div  >   <   / div  >  } } 

现在我在这里做第一次我在 viewbag 的基础上传递一些值我将成功消息呈现给最终用户并等待2秒后用户重定向到另一个页面 该页面名称为个人资料,如果用户点击了个人资料,重定向的页面现在是仪表板中的仪表板链接它回到这个页面和condtional div没有reneder。 一切顺利到这里!!! 如果我点击浏览器返回按钮它转到配置文件页面那里它检查div是否存在它在那里找到它并再次被重定向到仪表板页面 我想如果用户通过点击浏览器后退按钮而不是页面返回来自缓存。

您只需禁用缓存。 要禁用缓存,您可以使用

 <   meta     http-equiv   = 缓存控制     content   = < span class =code-keyword> no-cache,no-store,must-revalidate   < span class =code-keyword> /  >   <   meta     http-equiv   =  Pragma    content   =  no-cache    /  >    <   meta     http-equiv   = 过期    content   =  0    /  >   

或来自后面的代码

 Response.AppendHeader(  Cache-Control,  no-cache,no-store,must-revalidate);  //   HTTP 1.1。  Response.AppendHeader(  Pragma,  no-缓存);  //   HTTP 1.0。  Response.AppendHeader(  Expires,  0 );  //  代理。 

你好家伙的概念仍然在这里与ASHOK所描述的相同。 下面的代码,当我把它放在代码后面它适用。 < pre lang =vb> HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)) HttpContext.Current.Response.Cache.SetValidUntilExpires( false ) HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches) HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache) HttpContext.Current .Response.Cache.SetNoStore()

Hello guys, I am using following script in my page

<script>
           $(document).ready(function () {
               debugger;
               var checkId = document.getElementById("RedirectWindow");
               if (checkId != undefined) {
                   setInterval(function () {
                       window.location.href = "@Url.Action("Index", "Dashboard")";
                   }, 2000);
               }
           });
      </script>

Below is condition to render div

@{
         if(ViewBag.SuccessMessage!=null)
           {
            <div id="removeDiv">
                <div style="color: green" id="RedirectWindow">
                   <label>Profile updated successfully...</label>
            </div>
                 </div>
            }
    }

now i am doing here first time i am passing some value in viewbag based condition i render success message to end user and after waiting for 2 seconds user redirected to another page That page name is Profile and redirected page is dashboard now from dashboard if user clicks for profile link it goes back to this page and condtional div does not reneder. All goes fine till here!!! If i clicks on browser back button it goes to profile page there it checks if div is there it founds it there and gets redirected to dashboard page again I want if user goes back by clicking on browser back button instead of taking page from cache.

解决方案

(document).ready(function () { debugger; var checkId = document.getElementById("RedirectWindow"); if (checkId != undefined) { setInterval(function () { window.location.href = "@Url.Action("Index", "Dashboard")"; }, 2000); } }); </script>

Below is condition to render div

@{
         if(ViewBag.SuccessMessage!=null)
           {
            <div id="removeDiv">
                <div style="color: green" id="RedirectWindow">
                   <label>Profile updated successfully...</label>
            </div>
                 </div>
            }
    }

now i am doing here first time i am passing some value in viewbag based condition i render success message to end user and after waiting for 2 seconds user redirected to another page That page name is Profile and redirected page is dashboard now from dashboard if user clicks for profile link it goes back to this page and condtional div does not reneder. All goes fine till here!!! If i clicks on browser back button it goes to profile page there it checks if div is there it founds it there and gets redirected to dashboard page again I want if user goes back by clicking on browser back button instead of taking page from cache.

You just disable the cache. To disable cache you can use

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

Or from code behind

Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.

Hello guys concept still here is same as described by ASHOK . Below code when i put it in code behind it works for.

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1))
HttpContext.Current.Response.Cache.SetValidUntilExpires(false)
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache)
HttpContext.Current.Response.Cache.SetNoStore()

154