我尝试在响应头中设置Etag,但当我在浏览器中检查响应头时,我看不到它。顺便说一下,这只适用于Etag,我可以看到另一个标签和值。顺便说一句,我可以在本地主机上看到它,但当我发布代码到服务器时,我看不到。
public static void InsertETag(HttpResponseBase response, Model model)
{
try
{
var eTagValue = CalculateETag(model);
if (!string.IsNullOrEmpty(eTagValue))
{
var matchETagValue = HttpContext.Current.Request.Headers["If-None-Match"];
if (matchETagValue != null && matchETagValue == eTagValue)
{
response.SuppressContent = true;
response.StatusCode = 304;
response.StatusDescription = "Not Modified";
response.Headers["Content-Length"] = "0";
response.AppendHeader("ETag", eTagValue);
}
else
{
response.AppendHeader("ETag", eTagValue);
}
}
}
}
1条答案
按热度按时间y53ybaqx1#
从这里How to use ETag in Web API using action filter along with HttpResponseMessage