如何在从外部站点访问的包上启用缓存?

How to enable caching on a bundle accessed from an external site?

我正在尝试为添加到外部站点的 asp.net mvc 包启用客户端 js 缓存。目前该站点使用 url https://example.com/bundles/myscriptbundle 引用 js 包。

查看服务器的响应,我似乎总是得到 Cache-Control:"no-cache".

我尝试将以下内容添加到 global.asax.cs 但它似乎没有什么不同。关于如何将缓存 headers 添加到捆绑包的任何建议?

protected void Application_EndRequest(object sender, EventArgs e)
{

    var request = this.Request;
    var response = this.Response;

    if (request.RawUrl.Contains("bundles/"))
    {
         response.Cache.SetCacheability(HttpCacheability.Public);
         response.Cache.SetMaxAge(new TimeSpan(365,0,0,0));
         response.Cache.SetSlidingExpiration(true);
    }

原来是优化dll的一个版本。查看此答案了解详情

MVC4 Script Bundles Caching issue