Dav*_*ees 5 etag caching iis-6 last-modified http-status-code-304
您是否知道可以通过完全删除ETag和Last-Modifed响应头来阻止浏览器缓存中的文件重新验证以及随后的304响应?
当然,这在Apache中很容易,但在IIS 6中就像泥浆一样清晰.有谁知道如何在IIS中删除这两个头文件?
一种编程方式是使用HTTP模块,就像这样(基于Luke的SO答案):
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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
该模块通过web.config安装,<system.web>适用于IIS 6,安装在<system.webServer>IIS 7下.
| 归档时间: |
|
| 查看次数: |
3401 次 |
| 最近记录: |