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
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