首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从IIS删除Etag和Last-Modified标头

从IIS删除Etag和Last-Modified标头
EN

Stack Overflow用户
提问于 2010-10-11 22:20:17
回答 1查看 3.9K关注 0票数 5

你知道你可以通过完全删除ETag和Last- prevent the revalidation of files in browser cache and subsequent 304 response响应头来修改吗?

当然,这在Apache中很简单,但在IIS 6中就像mud一样清楚。有人知道如何在IIS中删除这两个头吗?

EN

回答 1

Stack Overflow用户

发布于 2010-10-11 22:32:09

一种编程方式是使用HTTP模块,如下所示(基于SO answer by Luke):

代码语言:javascript
复制
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>下。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3907042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档