'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")
    });
}


Solution 1:[1]

Disabling browser cache in ASP.NET core:

public class HomeController : Controller
{
    [ResponseCache(NoStore =true, Location =ResponseCacheLocation.None)]
    public IActionResult Index()
    {
        return View();
    }
}

Solution 2:[2]

Another way would be using an ASP-Attribute when you link your files in your _Layout.cshtml by using asp-append-version you will add a fresh hash everytime the file changed, so writing:

<script src="~/js/minime.js" asp-append-version="true"></script>

will in the end lead to:

<script src="/js/minime.js?v=Ynfdc1vuMOWZFfqTjfN34c2azo3XiIfgfE-bba1"></script>

so you get caching and the latest version out of the box.

Solution 3:[3]

[ResponseCache(Location = ResponseCacheLocation.None, Duration = 0, NoStore = true)]

Try adding an annotation above the controller class.It works for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mentor
Solution 2 Uwe Keim
Solution 3 Uwe Keim