Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda