我有这个 HttpModule 用于删除不需要的标头和缓存资产约 30 天,但它似乎不起作用。下面的代码和http响应:
回复:
Cache-Control private
Content-Type text/html; charset=utf-8
Content-Encoding gzip
Vary Accept-Encoding
Server Microsoft-IIS/7.5
X-AspNetMvc-Version 2.0
X-AspNet-Version 4.0.30319
X-Powered-By ASP.NET
Date Sat, 13 Nov 2010 20:13:57 GMT
Content-Length 1892
代码:
public class AssetCacheModule : IHttpModule
{
private static readonly List<string> _headersToRemove = new List<string> { "X-AspNet-Version", "X-AspNetMvc-Version", "Etag", "Server", };
private static readonly List<string> _longCacheExtensions = new List<string> {".js", ".css", ".png", ".jpg", ".gif",};
public void Init(HttpApplication context)
{
context.EndRequest += ContextEndRequest;
}
private static void ContextEndRequest(object sender, EventArgs e)
{
var context = HttpContext.Current;
_headersToRemove.ForEach(h => context.Response.Headers.Remove(h));
var extension = Path.GetExtension(context.Request.Url.AbsolutePath);
if (_longCacheExtensions.Contains(extension))
{
TimeSpan cacheDuration = TimeSpan.FromSeconds(44000);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetExpires(DateTime.Now.Add(cacheDuration));
context.Response.Cache.SetMaxAge(cacheDuration);
context.Response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
}
}
public void Dispose() { }
}
网络配置:
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="CuteWebUI.UploadModule" type="CuteWebUI.UploadModule,CuteWebUI.AjaxUploader"/>
<add name="AssetCacheModule" type="PostHope.Web.UI.AssetCacheModule, PostHope.Web.UI"/>
</httpModules>
我错过了什么???