1

I have wrote a simple IHttpModule

void context_PreSendRequestHeaders(object sender, EventArgs e)
{
    //remove default
    HttpContext.Current.Response.Headers.Remove("ETag");

    //add version one
    HttpContext.Current.Response.Headers.Add("ETag", "Test1.0");
}

where I want to remove IIS ETag and add my own for controlling javascript and css file requests from clients - as in case of update I want it will be refreshed automatically. the client response ok to the ETag

If-None-Match: Test1.0 If-Modified-Since: Mon, 02 Jun 2014 11:08:54 GMT

but the IIS always returns the content instead of 304

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
li-raz
  • 1,678
  • 2
  • 29
  • 57
  • possible duplicate of [How do I remove eTag headers from IIS7?](http://stackoverflow.com/questions/477913/how-do-i-remove-etag-headers-from-iis7) – Daniel A. White Jun 29 '14 at 19:32
  • the issue isnt removing the ETag, as I removed it and added my own. but when I added my own the IIS treats it as new request and never send 304 – li-raz Jun 29 '14 at 19:42

1 Answers1

0
void context_PreSendRequestHeaders(object sender, EventArgs e)
    {
        var etag = "Test4-0";

        //remove default
        HttpContext.Current.Response.Headers.Remove("ETag");

        //add version one
        HttpContext.Current.Response.Headers.Add("ETag", etag);

        string ifNoneMatch = HttpContext.Current.Request.Headers["If-None-Match"];
        Debug.WriteLine(String.Format("ifNoneMatch - {0}", ifNoneMatch));

        if (ifNoneMatch != null && ifNoneMatch.Contains(","))
        {
            ifNoneMatch = ifNoneMatch.Substring(0, ifNoneMatch.IndexOf(",", StringComparison.Ordinal));
        }

        HttpContext.Current.Response.Cache.VaryByHeaders["If-None-Match"] = true;
        Debug.WriteLine(String.Format("ifNoneMatch - etag: {0}-{1}", ifNoneMatch, etag));
        if (etag == ifNoneMatch)
        {
            Debug.WriteLine(String.Format("ifNoneMatch2 - etag: {0}-{1}", ifNoneMatch, etag));
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.NotModified;
            HttpContext.Current.Response.SuppressContent = true;
        }
    }
}
li-raz
  • 1,678
  • 2
  • 29
  • 57