473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Setting component expires header via a HttpModule

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
Sep 14 '08 #1
2 2515
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
Sep 14 '08 #2
Thanks for your reply. I'll check with my ISP to have the headers set
via IIS.

Sep 15 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steven | last post by:
Hi there, I have a database with documents that have event dates included. What I need to do is have the Expires META tag to be one day after that event date. Can I get the date from the...
0
by: Gil Strauss | last post by:
When using .net framework HttpWebRequest object, how can we set the connection header to "keep-alive" Acording to Microsoft ducomentation, setting the keepAlive property to true, should do the job,...
3
by: VP | last post by:
I would like to specify 'Expires' header for a js file. Can you please let me know where & how to specify that. Thanks.
4
by: Stac | last post by:
I have a web service which provides updates / additions to active directory. I can add accounts, change values etc, for everything I need to except the accountexpires field. I have been searching...
1
by: Asif | last post by:
Hi All, I did follow the MSDN article (http://msdn2.microsoft.com/en-us/ library/ms379585(VS.80).aspx ) for overriding Master Page properties by setting page title and other Meta information(...
0
by: Joe | last post by:
I'm trying to set the Expires property of a cookie in a control by doing the following: this.Context.Response.Cookies.Expires = DateTime.Today.AddDays(1); But when I refresh the page and check...
2
by: henryrhenryr | last post by:
I am trying to make my php-generated images cache. Here is a summary of the script with the headers. It doesn't seem to cache though. Do I need to do something special to make sure it caches? ...
0
by: helveticus | last post by:
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)....
8
by: JRough | last post by:
What is the purpose of caching in the header below? I used something like this for downloading a detail page to Excel but in this example it looks like it is for cache control? Why would you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.