Wednesday 15 July 2015

html - asp.net mvc : Images,Css files & javascript files are not being cached -


I do not want that to be my page cache for security and stability. When I press the back button on the browser, always go to the server to go to html.

I have achieved this by making the following procedure.

  public class NoCache: ActionFilterAttribute {public override request Onreshult Aksposting (Rijltaksinging Kantakt filter Contaks) {filterContext.HttpContext.Response.Cache.SetExpires (Dinanktaimkutisiano. Aided Day (-1)); FilterContext.HttpContext.Response.Cache.SetValidUntilExpires (wrong); FilterContext.HttpContext.Response.Cache.SetRevalidation (HttpCacheRevalidation.AllCaches); FilterContext.HttpContext.Response.Cache.SetCacheability (HttpCacheability.NoCache); FilterContext.HttpContext.Response.Cache.SetNoStore (); Base.OnResultExecuting (filterContext); }}   

I have applied to the filter to everything as a global filter

  public static void RegisterGlobalFilters (GlobalFilterCollection filter) Make sure cached pages are not served to any browser, including Chrome filters. Add (New Reject); }   

The problem was resolved. But now all images, CSS, and JavaScript files are not being cached. How do I tell it to cache?

You can try to be able to cash in web.config :

& lt; Clientcache & gt; element's and gt; Specifies the element cache related to the HTTP header, which sends the Internet Information Services (IIS) web client, which will cache the cash of the web client and proxy server IIS returns.

For example, httpExpires attribute a date and will expire content that specifies the time, and IIS response to a HTTP " End "headers. The httpExpires value attribute must be fully formatted date and time, which RFC 1123 follow the specification. For example:

  & lt; Configuration & gt; & Lt; System.webServer & gt; & Lt; StaticContent & gt; & Lt; Client Cache Cash ControlMode = "Usage Expiry" httpExpires = "Mars, 19 January 2038 03:14:07 GMT" /> & Lt; / StaticContent & gt; & Lt; /system.webServer> & Lt; / Configuration & gt;   

You can reference for more information.

No comments:

Post a Comment