Home > front end >  Prevent Caching Views in ASP.NET Core in VS 19
Prevent Caching Views in ASP.NET Core in VS 19

Time:02-18

I am new to ASP.NET core and I am trying to build a small web app but whenver I make a change to a view in debugging mode, I have to restart the application to see the new changes.

I tried few tricks but they did not work and even decorating a specific view with the filter

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

enter image description here

CodePudding user response:

First, Install Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.

Second, Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation.

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages()
        .AddRazorRuntimeCompilation();

    // code omitted for brevity
}

Then you can update the page without restart the project.

enter image description here

  • Related