问题描述
当我在IE10或Win7上的Chrome中单击后退"按钮时,它没有达到我的MVC控制器中的断点.IE开发人员工具中的网络"标签显示其304未修改,并且Fiddler没有捕获到请求.
When I click the back button in IE10 or Chrome on Win7, it does not hit my break point in my MVC controller. The Network tab in IE developer's tools shows it had a 304 not modified and Fiddler doesn't capture the request.
我希望回发帖子,所以我可以在控制器中进行工作.就我而言,该错误是:
I was expecting the post back, so I could do work in my controller.In my case, the bug is:
- 登录
- 确保您位于默认页面上
- 单击左上角的浏览器后退按钮,现在您将回到登录屏幕
- 当您再次使用相同的凭据登录做到这一点-我得到提供的防伪令牌是为用户"提供的,但当前用户为用户名".
我尝试将其放入控制器中,但未成功:
I've tried putting this in my controller, without success:
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中引起刷新?还是我的控制器方法实现不正确?
Is there a way to force the postback or detect this and cause a refresh in JavaScript? Or maybe I have my controller methods implemented incorrectly?
推荐答案
通常,这样的缓存规则并非以它们执行的逻辑为条件,整个URL要么被缓存,要么不被缓存.在这种情况下,这样简单的事情就足够了.
Typically caching rules like this aren't conditional upon the logic they perform, the URL as a whole is either cached or it isn't. In which case something as simple as this should suffice.
[OutputCache(NoStore=true, Duration=0)]
public ActionResult Login()
{
}
http://msdn.microsoft.com/en-us/library/dd492556(v = vs.108).aspx
这篇关于“后退"按钮不会导致回发到MVC中的控制器操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!