How to prevent browser cache for some files only in ASP.Net 5?

In the previous version, I would do it, as in here . But in the new version of ASP there is no web.config file, and I believe that this should be done in the launchSettings.json file.

Basically, what I want to do is stop caching the app.js file and all .html files from the templates folder. How to do it?

+4
source share
1 answer

Note that you can still add <meta> tags to your HTML pages for every page you don't want to cache:

<meta http-equiv="cache-control" content="no-cache" />

, IIS wwwroot ( , project.json), web.config ( IIS).

, Configure() Startup:

public void Configure(IApplicationBuilder application)
{
    application.Use(async (context, next) =>
    {
        context.Response.Headers.Append("Cache-Control", "no-cache");
        await next();
    });

    // ...
}

, HTTP- , PathString HttpRequest (Request HttpContext), ( , ), :

application.UseStaticFiles(new StaticFileOptions
{
    OnPrepareResponse = context =>
    {
        context.Response.Headers.Append("Cache-Control", "no-cache");
    }
};

, , , , - .

+6

Source: https://habr.com/ru/post/1624434/


All Articles