![](/img/trans.png)
[英]jquery.ajax - how to remove http headers from .net web service response
[英]Remove cache HTTP response headers from Web Api in Azure
我試圖從標准模式下托管在Azure網站上的Web Api 2項目的響應中刪除不需要的Cache-Control,Pragma和Expires HTTP標頭。
我在Global.asax Application_PreSendRequestHeaders中嘗試了以下操作:
var headers = ((HttpApplication)sender).Context.Response.Headers;
headers.Remove("Cache-Control");
headers.Remove("Pragma");
headers.Remove("Expires");
在Visual Studio中調試時可以使用。 但是在Azure上,僅刪除GET請求的標頭,而不刪除HEAD或POST請求的標頭。
感謝任何建議!
Azure網站支持請求篩選模塊,因此可以在web.config中執行此操作:
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Cache-Control" />
<remove name="Pragma" />
<remove name="Expires" />
</customHeaders>
</httpProtocol>
</system.webServer>
免責聲明:我不贊成刪除這些標頭,這是HTTP協議的重要組成部分。
刪除緩存標頭對客戶端說“完全由您決定如何緩存此響應”,這可能會導致生產中出現奇數且難以重現的錯誤。 如果要禁用緩存,則應將這些標頭設置為明確禁用緩存的值:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="-1" />
</customHeaders>
</httpProtocol>
</system.webServer>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.