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