.net 重新编译System.Web.Optimization以更改缓存头

.net 重新编译System.Web.Optimization以更改缓存头,.net,system.web.optimization,.net,System.web.optimization,我想重新编译System.Web.Optimization以更改Bundle.cs中的缓存头(CDN不喜欢Vary头),因为似乎没有其他方法覆盖头。我可以反编译源代码(通过Resharper),进行更改,然后重新编译源代码,但是当我将引用添加到我的项目时,所有依赖的Nuget包都会给出一个错误。类似于下面的一个 在未引用的程序集中定义了类型“System.Web.Optimization.IBundleBuilder”。必须添加对程序集“System.Web.Optimization,Versi

我想重新编译System.Web.Optimization以更改Bundle.cs中的缓存头(CDN不喜欢Vary头),因为似乎没有其他方法覆盖头。我可以反编译源代码(通过Resharper),进行更改,然后重新编译源代码,但是当我将引用添加到我的项目时,所有依赖的Nuget包都会给出一个错误。类似于下面的一个

在未引用的程序集中定义了类型“System.Web.Optimization.IBundleBuilder”。必须添加对程序集“System.Web.Optimization,Version=1.1.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”的引用


我宁愿不必编译所有依赖项。我也愿意使用其他方法覆盖缓存头。HTTPModules、IIS等。

我没有重新编译自定义版本的bundle,而是决定通过不同的HttpHandler路由bundle请求。URL中的快速替换允许我轻松获取捆绑包的内容,并使用我想要的缓存头将其写出。这不是最理想的方法,但很有效

不允许您在库中设置自己的标题是一个巨大的障碍。我希望他们能尽快解决这个问题

    public void ProcessRequest(HttpContext context)
    {
        var request = context.Request;
        var response = context.Response;
        var cache = response.Cache;

        var path = request.Url.LocalPath;
        var bundlesPath = "~/" + path.Substring(path.IndexOf("mypath"));
        bundlesPath = bundlesPath.Replace("mypath", "bundle");


        Bundle bundle = BundleTable.Bundles.GetBundleFor(bundlesPath);
        var bundleContext = new BundleContext(new HttpContextWrapper(HttpContext.Current), BundleTable.Bundles, bundlesPath);
        var bundleResponse = bundle.GenerateBundleResponse(bundleContext);

        cache.SetCacheability(HttpCacheability.Public);
        cache.SetExpires(DateTime.UtcNow.AddYears(1));
        cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));
        cache.SetValidUntilExpires(true);

        // This handler is called whenever a file ending 
        // in .sample is requested. A file with that extension
        // does not need to exist.
        response.ContentType = bundleResponse.ContentType;
        response.Write(bundleResponse.Content);
    }