簡體   English   中英

MVC4捆綁緩存頭

[英]MVC4 Bundling Cache Headers

我想更改從捆綁請求發送的緩存標頭。 目前它是由User-Agent改變但我不希望它,有沒有辦法更改捆綁請求發送的標頭?

在快速查看System.Web.Optimization程序集后,我可以看到標題在Bundle.SetHeaders中設置,這是一個私有靜態函數,所以我不認為它可能,盡管我希望被證明是錯誤的。

這不是我們目前公開的內容。 我們只在BundleResponse上暴露了IBundleTransform可能改變的Cacheability屬性。 是的,我們明確地設置了以下內容:

                HttpCachePolicyBase cachePolicy = context.HttpContext.Response.Cache;
                cachePolicy.SetCacheability(bundleResponse.Cacheability);
                cachePolicy.SetOmitVaryStar(true);
                cachePolicy.SetExpires(DateTime.Now.AddYears(1));
                cachePolicy.SetValidUntilExpires(true);
                cachePolicy.SetLastModified(DateTime.Now);
                cachePolicy.VaryByHeaders["User-Agent"] = true;

我們有一個工作項目我們的積壓工具打開它,並使其在未來更具可擴展性/可定制性。

正如janv8000對此響應的評論中提到的那樣,有一個解決方法。 您需要將以下URL重寫規則添加到Web服務器:

<system.webServer>
    <rewrite>
        <outboundRules>
            <rule name="Cache Bundles" preCondition="IsBundles" patternSyntax="ExactMatch">
                <match serverVariable="RESPONSE_Vary" pattern="User-Agent" />
                <action type="Rewrite" value="Accept-Encoding" />
            </rule>
            <preConditions>
                <preCondition name="IsBundles" patternSyntax="Wildcard">
                    <add input="{URL}" pattern="*/bundles/*" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
</system.webServer>

顯然,您需要注意將所有捆綁包放在捆綁包文件夾中或相應地更改IsBundles前提條件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM