6

当我在 IE10 或 Win7 上的 Chrome 中单击后退按钮时,它不会在我的 MVC 控制器中达到我的断点。IE 开发人员工具中的网络选项卡显示它有一个 304 未修改,并且 Fiddler 没有捕获请求。

我期待回复,所以我可以在我的控制器中工作。就我而言,错误是:

  1. 登入
  2. 确保您在默认页面上
  3. 单击左上角的浏览器后退按钮,您现在将返回登录屏幕
  4. 执行此操作时再次使用相同的凭据登录 - 我得到“提供的防伪令牌用于用户”,但当前用户是“用户名”。

我试过把它放在我的控制器中,但没有成功:

this.HttpContext.Response.CacheControl = "private";
this.HttpContext.Response.Cache.SetMaxAge(TimeSpan.FromSeconds(0));
public ActionResult Index()
{
    // Get: /Home/Index
    if (this.User.Identity.IsAuthenticated)
    {
        // send the user to the GlobalAssetDashboard
        return this.RedirectToAction(
            "GlobalAssetDashboard",
            "Dashboard",
            new
                {
                    area = "DashboardArea"
                });
    }

    return this.View("Login");
}
 public ActionResult Login()
{
    // GET: /Home/Login
    if (this.User.Identity.IsAuthenticated)
    {
        // send the user to the GlobalAssetList
        return this.RedirectToAction(
            "GlobalAssetDashboard",
            "Dashboard",
            new
                {
                    area = "DashboardArea"
                });
    }

    return this.View("Login", new LoginModel());
}

有没有办法强制回发或检测到这一点并导致 JavaScript 刷新?或者我的控制器方法实施不正确?

4

1 回答 1

17

通常,像这样的缓存规则不以它们执行的逻辑为条件,整个 URL 要么被缓存,要么不被缓存。在这种情况下,像这样简单的事情就足够了。

[OutputCache(NoStore=true, Duration=0)]
public ActionResult Login()
{

}

http://msdn.microsoft.com/en-us/library/dd492556(v=vs.108).aspx

于 2013-04-30T20:45:23.827 回答