IIS7 ASP.NET MVC 2 Asset Caching Module Not Working
I have this HttpModule that I am using to remove unwanted headers and cache assets for about 30 days but it does not seem to work. Code and http response below:
Response:
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
Code:
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() { }
}
web.config:
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, E开发者_C百科lmah"/>
<add name="CuteWebUI.UploadModule" type="CuteWebUI.UploadModule,CuteWebUI.AjaxUploader"/>
<add name="AssetCacheModule" type="PostHope.Web.UI.AssetCacheModule, PostHope.Web.UI"/>
</httpModules>
What am I missing???
If you're running in Integrated Pipeline mode in IIS7, HTTP modules go under:
<system.webServer>
<modules>
精彩评论