Button "Back" does not cause a reverse transfer of controller actions in MVC

When I click the back button in IE10 or Chrome on Win7, it does not affect my breakpoint in my MVC. The Network tab in IE Developer Tools shows that 304 has not been changed and Fiddler has not completed the request.

I was expecting the message to return, so I could work in my controller. In my case, the error is:

  • To come in
  • make sure you are on the default page
  • Click the "Back in Browser" button in the upper left corner. You will now be returned to the login screen
  • log in again with the same credentials when you do this - I get the โ€œProvided anti-fake token is for the userโ€, but the current user is โ€œusernameโ€.

I 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()); } 

Is there a way to force a response back or detect this and trigger an update in JavaScript? Or maybe my management methods are implemented incorrectly?

+4
source share
1 answer

Typically, caching rules like this are independent of the logic that they execute; the URL as a whole is either cached or not. In this case, just enough to do it.

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

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

+12
source

All Articles