我try 了这个中间件,但浏览器仍在保存文件.

我希望用户将总是得到最新版本的js和CSS文件.

public void Configure(IApplicationBuilder app)
{
    app.UseSession();
    app.UseDefaultFiles();
    app.UseStaticFiles(new StaticFileOptions
    {
        OnPrepareResponse = context =>
            context.Context.Response.Headers.Add("Cache-Control", "no-cache")
    });
}

推荐答案

还可以try 添加一个Expires页眉:

app.UseStaticFiles(new StaticFileOptions()
{
    OnPrepareResponse = context =>
    {
        context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
        context.Context.Response.Headers.Add("Expires", "-1");
    }
});

另一种方法是添加一个查询字符串,在开发中更改请求的结尾.在这种情况下,不需要中间件.

<environment names="Development">
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css?@DateTime.Now.Ticks" />
    <link rel="stylesheet" href="~/css/site.css?@DateTime.Now.Ticks" />
</environment>

Asp.net相关问答推荐

C# - 将 xyz 平铺转换为纬度/经度,反之亦然,给出不同的结果

你能从请求变量中确定时区吗?

SameSite 属性如何自动添加到我的 Asp.net_SessionID cookie 中?

文本框的输入按键触发事件

使用 ASP.NET WebForms 的 jQuery DataTables 服务器端处理

你如何确定哪个验证器失败了?

如何设置asp.net身份cookie过期时间

如何使用自动生成的列隐藏 ASP.NET GridView 中的列?

HttpModules 的执行顺序是如何确定的?

将通用列表绑定到转发器 - ASP.NET

如何在 ASP.net 中使用 wkhtmltopdf.exe

如何使div按钮提交其所在的表单?

使用 Twitter Bootstrap 在 @html.actionlink 中显示 html

如何进入 IIS 管理器?

如何将列表转换为数据表

如何直接在 .aspx 页面中访问 web.config 设置?

如何告诉 RadioButtonList 不生成表格

使用 ConfigurationManager.RefreshSection 重新加载配置而不重新启动应用程序

System.Threading.Tasks - 限制并发任务的数量

在 ASP.NET 中获取服务器的 IP 地址?