ASP.net ashx handler not caching?

Because you are using a handler you need to handle the caching headers in your own code, ie returning the 304 repsonse as well. So check the dates on the headers against the files and return 304's where appropriate We have code similar to the following at the start of some our image handlers var lastModified = this. LastModifiedFileTime(path); var isNotModified = this.

WriteConditional304(context, lastModified); if (isNotModified) return the two methods used look roughly as below protected bool WriteConditional304(HttpContext context, DateTime lastWrite) { if (context.Request. Headerssince! = null || context.Request.

HeaderseTag! = null) { try { DateTime date = context.Request. Headerssince!

= null? DateTime. Parse(context.Request.

Headerssince) : new DateTime(long. Parse(context.Request. HeaderseTag)); if (lastWrite WriteLine(ex.

Message); } } return false; } protected DateTime LastModifiedFileTime(string path) { FileInfo fi = new FileInfo(path); var modificationTime = fi. LastWriteTime; // negates the smaller parts of the date as the header doesn't carry them var date = new DateTime(modificationTime. Year, modificationTime.

Month, modificationTime. Day, modificationTime. Hour, modificationTime.

Minute, modificationTime. Second); return date; }.

Because you are using a handler you need to handle the caching headers in your own code, ie returning the 304 repsonse as well. So check the dates on the headers against the files and return 304's where appropriate. We have code similar to the following at the start of some our image handlers var lastModified = this.

LastModifiedFileTime(path); var isNotModified = this. WriteConditional304(context, lastModified); if (isNotModified) return; the two methods used look roughly as below. Protected bool WriteConditional304(HttpContext context, DateTime lastWrite) { if (context.Request.

Headerssince! = null || context.Request. HeaderseTag!

= null) { try { DateTime date = context.Request. Headerssince! = null?DateTime.

Parse(context.Request. Headerssince) : new DateTime(long. Parse(context.Request.

HeaderseTag)); if (lastWrite LastWriteTime; // negates the smaller parts of the date as the header doesn't carry them var date = new DateTime(modificationTime. Year, modificationTime. Month, modificationTime.

Day, modificationTime. Hour, modificationTime. Minute, modificationTime.

Second); return date; }.

I've put caching headers everywhere I know how to! Where am I missing them? – Tom Gullen Sep 14 at 1:43 see edits, for a further explanation you need to handle returning the 304 as well.

– kmcc049 Sep 14 at 1:54.

Cache this handler response for 1 hour. HttpCachePolicy c = context.Response. WebRequest request = WebRequest.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions