开发者

Prevent caching on ASP MVC site running on IIS 7.5

I have an ASP MVC 3 site running on IIS 7.5 and I cant prevent it from caching.

I have disabled the output caching in IIS by adding a '* Do Not Cache' entry to the website and also added an action filter on the controller on result execute that prevents caching too (see code below) but when I use the site, it's still caching. I have deleted all history and cookies etc from Internet Explorer and Firefox but I still see old data.

Does anyone have any ideas or suggestions on what else I can 开发者_Python百科do to try and prevent this?

Thanks in advance,

James

UPDATE

I have dug further using the SQL profiler and it seems to be the SQL server caching the query. Could this be the case?

2nd UPDATE

I now know if definitley NOT SQL caching, now looking at IIS and MVC

SOLVED!!!

It was NHibernate!

It was using the same session for every call rather than a session per request.

    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
        filterContext.HttpContext.Response.Cache.SetRevalidation    (HttpCacheRevalidation.AllCaches);
        filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        filterContext.HttpContext.Response.Cache.SetNoStore();

        base.OnResultExecuting(filterContext);
    }


you could try adding OutputCach attribute to the action and set the duration to a couple seconds. Ex: [OutputCache(Duration=1, VaryByParam = "none")]


Are you calling your MVC action via JQuery ajax? If so, see this: http://www.peteonsoftware.com/index.php/2010/08/20/the-importance-of-jquery-ajaxsetup-cache/


It's not as simple as the problem being in the browser cache itself is it? try adding a no-cache meta tag?

<HTML><HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD><BODY>
</BODY>
</HTML>

Just a thought, also you can set the no-cache header. Maybe use Fiddler to check the browsers not caching the response.


SOLVED!!!

It was NHibernate!

It was using the same session for every call rather than a session per request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜