views:

129

answers:

1

I have an IHttpHandler similar to AssemblyResourceLoader. What it does is generate an image and then send it back to the browser.

In AssemblyResourceLoader there is a code block like this:

    HttpCachePolicy cache = context.Response.Cache;
    cache.SetCacheability(HttpCacheability.Public);
    cache.VaryByParams["d"] = true;
    cache.SetOmitVaryStar(true);
    cache.SetExpires(DateTime.Now + TimeSpan.FromDays(365.0));
    cache.SetValidUntilExpires(true);
    Pair assemblyInfo = GetAssemblyInfo(assembly);
    cache.SetLastModified(new DateTime((long) assemblyInfo.Second));

I have set up mine to emit the exact same headers as AssemblyResourceLoader. I set the Last-Modified header and the browser sends the If-Modified-Since header to my handler just as it does with AssemblyResourceLoader. The problem is this: My handler never returns the 304 like AssemblyResourceLoader does. I can't find anywhere in the AssemblyResourceLoader code where it deals with the If-Modified-Since header so I don't know how to deal with it myself. Does anybody know where ASP.Net does that and how I can get the same behavior out of my handler?

Thanks.

A: 

Looks like you need to do it yourself, but it's not hard: http://www.motobit.com/tips/detpg_net-last-modified/

Steven Sudit
Also: http://stackoverflow.com/questions/1917586/http-cache-check-with-the-server-always-sending-if-modified-since
Steven Sudit
For general information: http://www.mnot.net/cache_docs/
Steven Sudit
I like that but I'd prefer not to do it myself. AssemblyResourceLoader doesn't do anything. I'm thinking there's something in asp.net that handles it so I'd like to be able to take advantage of that.
Matthew
Hmm, did the stackoverflow link help any, either?
Steven Sudit
Not so much since it's talking about "Expires" header and I'm looking for information about how ASP.Net handles "If-Modified-Since" header.
Matthew
Thinking about it a little more, even if ASP.Net can handle that header, how is it supposed to know when it was modified without me telling it? The correct solution is to deal with it myself. Thanks for the link.
Matthew
That makes sense to me. I suppose if you set a Last-Modified or ETag header, ASP.NET could immediately compare it against the value of If-Modified-Since or If-None-Match and silently end your execution if it's not newer. But it doesn't, so that's up to you. Please do check out the second link, since it explains about headers you need to return to ensure that the client knows it's ok to send those If-* headers in its request.
Steven Sudit