I am experiencing a problem with IE caching the results of an action method.
Other articles I found were related to security and the [Authorize] attribute. This
MVC doesn't cache the results. IE does.
So you have to tell IE not to do it.
Here's how I do it. First, an attribute:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public sealed class CacheControlAttribute : ActionFilterAttribute
{
public CacheControlAttribute(HttpCacheability cacheability)
{
this._cacheability = cacheability;
}
public HttpCacheability Cacheability { get { return this._cacheability; } }
private HttpCacheability _cacheability;
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache;
cache.SetCacheability(_cacheability);
}
}
Next, an action:
[CacheControl(HttpCacheability.NoCache), HttpGet]
public JsonResult MyAction()