For selfhost (without IIS), you can build an attribute class derived from the System.Web.Http.Filters.ActionFilterAttribute type (in the assembly system.web.http.net 4.0+). Then override the OnActionExecuted method as shown below:
public class NoResponseCachingAttribute : ActionFilterAttribute { public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { if (actionExecutedContext.Response.Headers.CacheControl == null) actionExecutedContext.Response.Headers.CacheControl = new System.Net.Http.Headers.CacheControlHeaderValue(); actionExecutedContext.Response.Headers.CacheControl.NoCache = true; actionExecutedContext.Response.Headers.CacheControl.NoStore = true; actionExecutedContext.Response.Headers.CacheControl.MustRevalidate = true; base.OnActionExecuted(actionExecutedContext); } }
This approach worked for my application.
source share