0
Answer

How to avoid Connection: close when Response.StatusCode = 304 is set

srikanth

srikanth

15y
4.1k
1

I am trying to improve site (developed on ASP.NET/IIS6.0) performance by reducing network traffic between client & server, by setting expiration for static files(js, jpg, gif, css etc) so that I can avoid 304 responses from server.
For that I have written a http module, in begin request event I am trying to set the expires header for the file, so that I can avoid further requests from client.
private void BeginRequest(object sender, EventArgs e){HttpContext.Current.Response.Expires = 15;}
Everything seem to be working fine, but when the set expiration date is crossed (expired), further requests I am seeing that the content is downloded again. Which I dont want to do that way, because there is no change in the modified date.
So for that, I tried to explicitly set the response.code to 304.
if
(HttpContext.Current.Request.Headers["If-Modified-Since"] != null ){HttpContext.Current.Response.StatusCode = 304;}
With this, header Connection is set to close. ( Connection: close) Which  I am assuming might be a problem. Is this a problem, can it be avoided?
I tried different alternatives of setting expiration, last modified since, last modified headers, but I could not got proper solution.
Any help in resolving this is higly appreciable.