我写了一个简单的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");
}如果我想删除IIS,并添加自己的ETag来控制来自客户端的javascript和css文件请求--就像我想要的更新一样,它将被自动刷新。客户端对ETag的响应正常
如果-无-匹配:Test1.0if-修改-自:星期一,2014年6月2日11:08:54格林尼治时间
但是IIS总是返回内容而不是304
发布于 2014-06-29 20:07:43
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;
}
}
}https://stackoverflow.com/questions/24479430
复制相似问题