Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Setting component expires header via a HttpModule

Reply
Thread Tools

Setting component expires header via a HttpModule

 
 
helveticus
Guest
Posts: n/a
 
      09-14-2008
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(HttpCacheabilit y.Public)
End If
End Sub
End Class
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      09-14-2008
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)


helveticus wrote:
> 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(HttpCacheabilit y.Public)
> End If
> End Sub
> End Class

 
Reply With Quote
 
 
 
 
helveticus
Guest
Posts: n/a
 
      09-15-2008
Thanks for your reply. I'll check with my ISP to have the headers set
via IIS.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
Setting component expires header via a HttpModule helveticus ASP .Net 0 09-14-2008 06:21 PM
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); Tine Müller XML 1 07-28-2007 01:05 PM
Specifying 'Expires' header for JS file VP ASP .Net 3 09-14-2005 07:43 AM
setting Expires HTTP response header Mark Volkmann Ruby 2 07-17-2005 02:36 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57