Last post Sep 22, 2006 12:54 PM by Paulo Pereira
Sep 19, 2006 08:44 AM|JeffreyABecker|LINK
I'm trying to write a handler which serves out images based on url parameters. Ideally I'd like these images to be cached so that they're not being reloaded every single time. I'm currently explicitly setting Response.CacheControl = "public" in my handler
yet somewhere this is being overwritten and the images are being served out with Cache-Control: private. Does anyone have and ideas as to why this is happening?
Sep 22, 2006 12:54 PM|Paulo Pereira|LINK
Great question! I've had a similar problem while creating a custom handler to service copyright protected images. All images were in their original format at the server, and the handler produced "water marked" versions. At the time, I had to "dig" for a
while to come up with an answer. Here's what I came up with.
explicitly set the cache-control HTTP header to "public", at the ProcessRequest method of the handler, the ASP.NET runtime ensures that this header will only contain that value if the user is not authenticated. This is done by the HttpModule that performs
OutputCaching upon request servicing completion (if you want to see it yourself, take a look at the System.Web.dll source code, in particular the OnLeave method of System.Web.Caching.OutputCacheModule class). This means that the header value is replaced by
"private" just before the response is sent to the client.
One way to control this
behavior is to disable authentication (check if your web.config contains
mode="Windows" />, the default value used by VS.NET 2005).
Despite this possible solution, the main question remains unanswered! Why? The following justification satisfied me at the time.
If you consider the proxy as part of the communication channel (note that it is a public cache), it may make sense to ensure that the response content is not stored there, when authentication is involved.