tags:

views:

780

answers:

1

In IIS7 I am trying to set a really far future expires header for all content that have the file name that has a specific word in it. For example I would like to set this header on any file being requested from IIS7 that is

*cached*.js

I know that it is possible to set far future expires headers, But I want to know if it is possible to set it on specific files like in the example above.

I want to use this method on a .NET application I am trying to serve up, but I want to make it more efficient so that certain files will be cached for a very long time, because it virtually never changes. At the same time I don't want to be restricted to doing it for all files in a certain folder or all files of certain type.

I am open to doing this through modifying my Asp.Net application to achieve this, or through IIS7 settings.

So guys, what do you think, is There a way to do this?

+1  A: 

An HttpModule will let you do this. That would let you look at the incoming URL then add the correct response headers.

Edit: Added Example

You can use this URL to create a basic HttpModule. Then in the Application_BeginRequest event, I think this code will be close to what you want:

if (context.Request.FilePath.ToLower().IndexOf("cached") != -1)
    context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
David
Do you know any place I can find examples of writing a HttpModule I could use to get started?
Roberto Sebestyen
I've added an example...
David
Thanks I will try that :-)
Roberto Sebestyen