Setting component expires header via a HttpModule

H

helveticus

I'm having difficulties setting the expires header for images and css
files in my compression HttpModule. Compression is carried out by
context_BeginRequest and works fine (code not shown). However, I
can't set the expiration header for selected file extensions (ie. gif
and css). Firebug' s YSL reports that these components do not have a
far future Expires header.

Question: How should I modify the code to set the expires header? TIA
for any hints.

Public Class CompressionModule
Implements IHttpModule

Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
End Sub

Public Sub Init(ByVal context As System.Web.HttpApplication)
Implements System.Web.IHttpModule.Init
AddHandler context.BeginRequest, AddressOf
context_BeginRequest ' Carries out compression
AddHandler context.EndRequest, AddressOf
context_EndRequest
End Sub

Public Sub context_EndRequest(ByVal sender As Object, ByVal e
As EventArgs)
Dim app As HttpApplication = CType(sender,
HttpApplication)

If app.Response.ContentType = "image/gif" Or
app.Response.ContentType = "text/css" Then
app.Response.ExpiresAbsolute =
DateTime.Now.AddMinutes(5)

app.Response.Cache.SetCacheability(HttpCacheability.Public)
End If
End Sub
End Class
 
B

bruce barker

gif & css (and other static files) are not mapped to asp.net by default.
you will need to update the mapping in iis. there is a performance hit
using asp.net to server static content. you can also tel iis to set the
cache headers for certain extensions.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top