Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable browser cache in ASP.NET core rc2?

I tried this Middleware but the browser still saving files.

I want user will always get the last version of js and css files.

public void Configure(IApplicationBuilder app) {     app.UseSession();     app.UseDefaultFiles();     app.UseStaticFiles(new StaticFileOptions     {         OnPrepareResponse = context =>             context.Context.Response.Headers.Add("Cache-Control", "no-cache")     }); } 
like image 664
David Munsa Avatar asked Jul 06 '16 18:07

David Munsa


People also ask

How do I disable API cache?

Just use the Cache-Control: no-cache header. Implement it as delegating-Handler and make sure your header is applied (with MS Owin Implementation hook up on OnSendingHeaders() .

How do I disable index html cache?

In the root web. config we specify that we don't want to the index. html to cache by setting the cache-control , Pragma and Expires request headers as well as the max-age to 0.


1 Answers

Disabling browser cache in ASP.NET core:

public class HomeController : Controller {     [ResponseCache(NoStore =true, Location =ResponseCacheLocation.None)]     public IActionResult Index()     {         return View();     } } 
like image 129
Mentor Avatar answered Sep 29 '22 18:09

Mentor