【问题标题】:Prevent browser back button to redirect to the previous page in asp.net mvc2防止浏览器后退按钮重定向到asp.net mvc2中的上一页
【发布时间】:2013-04-13 21:35:28
【问题描述】:

我使用以下文章创建了一个关于在 asp.net mvc2 应用程序中显示会话过期警告消息的 POC。 http://www.fairwaytech.com/2012/01/handling-session-timeout-gracefully/

我在代码中做了一处改动,如下所述:

location.href = expireSessionUrl;在endSession方法中改成如下代码:

window.location.replace(expireSessionUrl);

一旦用户单击“会话警告消息”对话框中的“注销”按钮,他就会导航到“注销”视图。但是在这里,如果他点击浏览器的后退按钮,他会被导航到上一页。

我有下面提到的修改过期方法:

[Authorize]
public virtual ActionResult Expire()
{
Session.Clear();
FormsService.SignOut();
HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Response.Cache.SetValidUntilExpires(false);
HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Response.Cache.SetNoStore();
return Redirect(“/”);
}

请您指导我解决问题。

提前致谢 桑托什库马尔帕特罗

【问题讨论】:

    标签: asp.net asp.net-mvc-2


    【解决方案1】:

    你需要让你的缓存过期,试试这个:

    Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
    

    或来自docs

    Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
    Response.Cache.SetCacheability(HttpCacheability.Public);
    Response.Cache.SetValidUntilExpires(true);
    

    或者您可以使用Response.CacheControl 来控制页面在用户缓存中的存储方式

    【讨论】:

    • 感谢您的回复。但它现在也不起作用。我可以单击浏览器的后退按钮并导航到以前访问过的页面。
    猜你喜欢
    • 1970-01-01
    • 2013-01-11
    • 2017-05-23
    • 2015-10-22
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 2011-10-15
    相关资源
    最近更新 更多