4

We are using system of hidden internal sites. For hiding path we are using HttpContext.RewritePath. There is also a system for uploading photos that generates new name, and photo has no chance to change. We want to use client cache for such photos.

Url on site, that is visible for users: /files/autoupload/1/13/wufkjqr31028.jpg.[ps].jpg

Url after HttpContext.RewritePath on server: /_sites/_shared/files/autoupload/1/13/wufkjqr31028.jpg.[ps].jpg

There is web.config in "/_sites/_shared/files" folder with client cache settings:

<system.webServer>
    <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
    </staticContent>
</system.webServer>

If "/files/autoupload/1/13/wufkjqr31028.jpg.[ps].jpg" url is requested, this settings does no apply at all. There is no Cache-Control header in response.

If full url "/_sites/_shared/files/autoupload/1/13/wufkjqr31028.jpg.[ps].jpg" is requested and our HttpContext.RewritePath skips it, cache settings works.

But if i create "/files" folder in root with same web.config, cache settings begins to work with original "/files/autoupload/1/13/wufkjqr31028.jpg.[ps].jpg" url.

So web.config client cache settings only applies by originally requested disk path and does not apply by rewritten path.

Is there any way to fix this other than creating folders in root?

Omnik
  • 161
  • 9

1 Answers1

0

Your web.config has a configuration element for staticContent while you rewrite the url, making it dynamic so your config does not apply.

It is possible to create your own HTTP handler and to map it to any file extension you would like to. Within the implementation of your handler you can set almost any HTTP header, in your case cache control headers. See IHttpHandler interface here and here about configuring it see section 14.9 Cache-Control here

Kees
  • 1,408
  • 1
  • 15
  • 27