IIS去除无用的HTTP响应头

IIS去除无用的HTTP响应头

最开始的做法

修改Web.config配置文件去除X-AspNet-Version、X-Powered-By

<system.web>
    <!--关闭ASP.Net版本号-->
    <httpRuntime enableVersionHeader="false"/>
  </system.web>
<system.webServer>
    <httpProtocol>
      <customHeaders>
        <!--去除请求头-->
        <remove name="X-Powered-By"/>
      </customHeaders>
    </httpProtocol>
  </system.webServer>

在Global.asax.cs增加方法

		protected void Application_PreSendRequestHeaders()
        {
            Response.Headers.Remove("Server");//禁用Server HTTP头
        }

遇到的问题

访问静态文件时,Server请求头依然存在,会被AppScan扫描出来。

解决方案

StripHeaders,一个 C++ 开发的开源模块,使用 WIN32 API 在 IIS 核心执行,能涵盖静态内容,核心模块的 Overhead 低,加上原生程序执行效能远比 .NET 程序快,较不用担心效能问题。
下载iis_stripheaders_module_1.0.5.msi后直接双击安装即可,会看到窗口加载后,无提示,无需再次安装。

下载地址https://github.com/Dionach/StripHeaders/releases/tag/v1.0.5

安装程序在背后做了一堆事:

Installs stripheaders.dll
Registers the Native-Code module with IIS using the appcmd.exe command
Extends the IIS configuration schema to allow setting of headers to remove
Adds default settings to the IIS configuration to remove the common "Server", "X-Powered-By" and "X-Aspnet-Version" respon se headers
Adds a registry setting to remove the "Server: Microsoft-HTTPAPI/2.0" response header.

验证安装成功
在这里插入图片描述
在这里插入图片描述
StripHeaders 默认会移除 Server、X-Powered-By、X-AspNet-Version 等 Response Header,不需做额外的配置就会生效。 若需移除额外 Header,则可在 web.config system.webServer/stripHeaders 中设定。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值