![](/img/trans.png)
[英]How to enable nginx reverse proxy to work with gRPC in .Net core?
[英]How to force updates / prevent HTML caching of .NET Core web application running on Linux and hosted by an nginx reverse proxy server
我使用 .NET Core 5.0 MVC 用 C# 编写了我的 Web 应用程序。 我在控制器中使用路由来将 URLS 映射到使用 Razor 的视图并提供服务。 我使用 .Net 核心运行时在 Linux 服务器上运行该应用程序,然后使用 nginx 反向代理服务器托管该应用程序。
我经常对我的网站进行更改,它依赖于从我的数据库中实时拉取数据来获取最新的统计数据以显示给用户,因此我提供的视图是最新的至关重要。
问题:出于某种原因,我可以发布和部署新代码,它会在我的桌面上正常显示,但不能在移动设备或我朋友的桌面上显示(有时会,有时不会)。 如果我将 google.com/test 之类的 URL 稍微更改为 google.com/Test,我可以看到新的变化。 我的路径也不区分大小写,但我所有的 SEO/google 链接都有小写/缓存版本。
经过研究,我得出结论,不同的浏览器/应用程序正在缓存我的 HTML/JS/CSS,而不是从服务器获取最新的。
我尝试了以下方法:
安装 NuGet 包“Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation”并调用
services.AddControllersWithViews().AddRazorRuntimeCompilation();
在我的 ConfigureServices 方法中。
将以下内容添加到我的布局文件中:
<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" />
将此添加到返回视图的控制器操作中:
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
我正在使用 nginx 反向代理服务器托管我的 Web 应用程序服务器,并且我尝试添加一些我在网上看到的内容以防止没有运气的缓存。
我的移动设备(运行 Chrome 的 Android)没有任何效果。
有没有其他人遇到过这个或可能知道解决方案?
您是否尝试过使用 ASP.NET 提供的asp-append-version ?
它可以以这种方式用于 css/js
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.