[英]Setting Owin Cache Control headers in ASP.net Web API
我有以下代碼:
public class CacheHeader : OwinMiddleware
{
public CacheHeader(OwinMiddleware next)
: base(next)
{
}
public override async Task Invoke(IOwinContext context)
{
context.Response.Headers["Cache-Control"] = "no-cache, no-store, must-revalidate";
context.Response.Headers["Pragma"] = "no-cache";
context.Response.Headers["Expires"] = "0";
await Next.Invoke(context);
}
}
應該將Http緩存控制標題更改為“no store,no-cache”,但是當我在Chrome Dev工具中檢查它時,我得到以下內容:
Cache-Control:no-cache
Connection:keep-alive
Host:10.0.211.202
Pragma:no-cache
有沒有理由我無法將緩存控制中的內容從無緩存更改為無緩存,無存儲?
在注冊web api之前,請務必介紹您的中間件:
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
app.Use((context, next) =>
{
context.Response.Headers["Cache-Control"] = "no-cache, no-store, must-revalidate";
context.Response.Headers["Pragma"] = "no-cache";
context.Response.Headers["Expires"] = "0";
return next.Invoke();
});
app.UseWebApi(config);
}
}
只是一個猜測。 您是否嘗試在next.Invoke()之后設置響應標頭?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.