你知道你可以通过完全删除ETag和Last- prevent the revalidation of files in browser cache and subsequent 304 response响应头来修改吗?
当然,这在Apache中很简单,但在IIS 6中就像mud一样清楚。有人知道如何在IIS中删除这两个头吗?
发布于 2010-10-11 22:32:09
一种编程方式是使用HTTP模块,如下所示(基于SO answer by Luke):
namespace HttpModules
{
using System;
using System.Web;
public class RemoveExtraneousHeaderModule : IHttpModule
{
/// <summary>
/// Initializes a module and prepares it to handle requests.
/// </summary>
/// <param name="context">Provides access to the request context.</param>
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += this.OnPreSendRequestHeaders;
}
/// <summary>
/// Disposes of the resources (other than memory) used by this module.
/// </summary>
public void Dispose()
{
}
/// <summary>
/// Event raised just before ASP.NET sends HTTP headers to the client.
/// </summary>
/// <param name="sender">Event source.</param>
/// <param name="e">Event arguments.</param>
protected void OnPreSendRequestHeaders(object sender, EventArgs e)
{
NameValueCollection headers = HttpContext.Current.Response.Headers;
headers.Remove("Server");
headers.Remove("ETag");
headers.Remove("X-Powered-By");
headers.Remove("X-AspNet-Version");
headers.Remove("X-AspNetMvc-Version");
}
}
}该模块通过web.config安装,对于IIS6在<system.web>下,对于IIS7在<system.webServer>下。
https://stackoverflow.com/questions/3907042
复制相似问题