Setting component expires header via a HttpModule

H

helveticus

I'm having difficulties setting the expires header for selected
components in my compression HttpModule. The compression part carried
out by context_BeginRequest works fine (code not shown). However, I
can't set the expiration header for file extensions (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
AddHandler context.EndRequest, AddressOf
context_EndRequest
End Sub

Public Sub context_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
' Carries out compression. Works fine.
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
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top