我使用 Asp.Net Core RC2 和 Kestrel 作为我的 Web 服务器。我需要确保使用无缓存 header 响应请求(在这种情况下为所有请求),以便浏览器获得最新版本(不是 304)。
在 Startup 中有没有办法配置 Kestrel 或有办法将此步骤注入(inject)管道?
编辑:在我的情况下,无商店可能是更好的选择:https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching “不允许缓存无存储响应,并且必须在每次请求时全部获取。”
最佳答案
您可以使用中间件来处理 header 。例如,您可以通过将以下内容添加到 Startup 的 Configure 方法的顶部来强制 no-cache 缓存控制:
app.Use(async (httpContext, next) =>
{
httpContext.Response.Headers[HeaderNames.CacheControl] = "no-cache";
await next();
});
关于asp.net - 如何向 Kestrel 响应添加无缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36987688/