我希望重新编译System.Web.Optimization以更改Bundle.cs中的缓存头(CDN不像like头),因为似乎没有其他方法来覆盖这些头。我能够解压缩源代码(通过Resharper),进行更改,并重新编译源代码,但是当我将引用添加到我的项目时,所有依赖的Nuget包都会出现错误。与下面的类似。
类型'System.Web.Optimization.IBundleBuilder‘是在未引用的程序集中定义的。必须添加对程序集'System.Web.Optimization,Version=1.1.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35‘的引用
我宁愿不必编译所有的依赖项。我还可以使用其他方法覆盖缓存头。HTTPModules、IIS等。
发布于 2014-08-08 05:29:53
我没有重新编译包的自定义版本,而是决定通过不同的HttpHandler路由包请求。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);
}https://stackoverflow.com/questions/24881630
复制相似问题