在以前的版本中,我会像在 here 中那样做.但是在新版本的 ASP 中没有 web.config 文件,我认为应该在 launchSettings.json 文件中完成。
基本上我想做的是停止缓存 app.js 文件和模板文件夹中的所有 .html 文件。我该怎么做?
最佳答案
请注意,您仍然可以随意添加 <meta
> 您不想缓存的每个页面的 HTML 页面中的标记:
<meta http-equiv="cache-control" content="no-cache" />
另请注意,如果您要部署到 IIS,那么您仍然有
wwwroot
(或您在 project.json
中指定的内容),您可以在其中放置 web.config
文件(由 IIS 解析)。如果你想用配置来做,那么添加一个
Configure()
您的 Startup
中的方法类(class):public void Configure(IApplicationBuilder application)
{
application.Use(async (context, next) =>
{
context.Response.Headers.Append("Cache-Control", "no-cache");
await next();
});
// ...
}
请注意,如果您只想将该 HTTP header 应用于某些页面,您只需检查
PathString
HttpRequest
的属性(property)( Request
的属性 HttpContext
)或者如果您需要为每个静态文件使用它(如果您只想应用于其中的一些,则与上述相同)使用:application.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = context =>
{
context.Response.Headers.Append("Cache-Control", "no-cache");
}
};
您应该发送哪些 header 以与您需要支持的浏览器兼容已在 Making sure a web page is not cached, across all browsers 上讨论过。 .
关于asp.net - 如何仅在 ASP.Net 5 中防止某些文件的浏览器缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34811551/