Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
How to force updates / prevent HTML caching of .NET Core web application running on Linux and hosted by an nginx reverse proxy server

I wrote my web application in C# using .NET Core 5.0 MVC. I am using routing in the controller to map URLS to and serve Views that use Razor. I run the application on a Linux server using the .Net core runtime and then host the application using an nginx reverse proxy server.

I make frequent changes to my website and it relies on real-time pulls from my database to get the latest stats to show to the user so it is vital that the views I serve are up to date.


PROBLEM: For some reason, I can publish and deploy new code and it'll show up fine on my desktop but not on mobile or my friends desktops (sometimes it does sometimes it doesn't). I can see new changes if I change the URL slightly like google.com/test to google.com/Test. My paths are not case-sensitive either but all of my SEO/google links have the lowercase/cached version.


After researching, I concluded that the different browsers/apps are caching my HTML/JS/CSS and not getting the latest from the server.

I have tried the following:

  • Installing the NuGet Package "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" and calling

      services.AddControllersWithViews().AddRazorRuntimeCompilation();
    

in my ConfigureServices method.

  • Adding the following to my layout file:

      <meta http-equiv="cache-control" content="max-age=0" />
      <meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
      <meta http-equiv="expires" content="-1" />
      <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
      <meta http-equiv="pragma" content="no-cache" />
    
  • Adding this to my controller actions that return the views:

    [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
    
  • I am hosting my web app server using an nginx reverse proxy server, and I tried adding some of the stuff I saw online to prevent caching with no luck.

Nothing has worked consistently for my Mobile Device (Android running Chrome).

Has anyone else encountered this or possibly know of a solution?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Have you tried to use asp-append-version which is provided by ASP.NET ?

It can be used this way for css/js

        <link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda