Back button not requesting asp.net mvc get method

强颜欢笑 提交于 2019-12-04 03:55:34

问题


We are facing a specific problem where in on click of backbutton, the default get method is not getting triggered in asp.net mvc

any specific solutions ?


回答1:


If the browser has the page cached, it'll use the one from cache.

Try telling the response not to cache. You can do it with an ActionFilter or globally in Global.asax.

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

More options here:

Disable browser cache for entire ASP.NET website




回答2:


if you want just one specific action to get from server every time use

[OutputCache(NoStore = true, Duration = 1)]

as an attribute on your action like this

    [HttpGet]
    [OutputCache(NoStore = true, Duration = 1)]
    public ActionResult Index()
    {
        ........
    }



回答3:


Try this in your HTML section:

<meta http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE">

That will stop the page from being cached by your browser.



来源:https://stackoverflow.com/questions/7224524/back-button-not-requesting-asp-net-mvc-get-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!