XOR
XOR

Reputation: 2167

Using VirtualPathProvider for simple static files

We are using custom VirtualPathProvider to serve files from ASP.NET-based web site. To serve static files, like images, css and scripts, we explicitly stated that StaticFileHandler should be used for files with this extension. Like this:

<add verb="GET" path="*.jpg" type="System.Web.StaticFileHandler"></add>

All of this seems logical and works except one fact - all virtual files served with this handler are coming to client with "Cache-Control: private" header. This is not what I would expect for static file.

Is there any good way to make those files cacheable?

Additional info:

  1. Yes, it's possible to add cache header in a simple HttpModule that would add it for all ".js" files, but this is not good way.
  2. I've found this post, that seems related to our problem. It refers to KB947461. But it's not clear, is this patch still not applied to the framework? Almost a year passed. And where to get it, if not.

Update: Looks like patch from KB947461 is included in .NET Framework 3.5 SP1. And we already have it installed.

Update 2: For now we've ended up with this HttpModule that add cache headers if current handler is StaticFileHandler. But this is definitely a crutch.

Upvotes: 4

Views: 2145

Answers (2)

mcintyre321
mcintyre321

Reputation: 13306

Unbelievable that the built in one doesn't do it. This looks promising: http://code.google.com/p/talifun-web/wiki/StaticFileHandler

Upvotes: 2

pedrofernandes
pedrofernandes

Reputation: 16854

Try Active Cache in IIS, WebSite properties and Cache Tab. In my case works very well.

Upvotes: 0

Related Questions