没有所谓的捷径
一切都是时间最平凡的累积

IIS去除无用的HTTP响应头,屏蔽返回的Header中的IIS版本信息

本文最后更新:2023年10月8日,已超过203天未更新,如果文章内容失效,请留言反馈本站。

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 中设定。

» 站长码字辛苦,有用点个赞吧,也可以打个
» 若转载请保留本文转自:豫章小站 » 《IIS去除无用的HTTP响应头,屏蔽返回的Header中的IIS版本信息》
» 本文链接地址:https://blog.mydns.vip/4794.html
» 如果喜欢可以: 点此订阅本站 有需要帮助,可以联系小站
赞(0) 打赏
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除,联系邮箱:contact@mydns.vip。文章观点不代表本站立场。本站原创内容未经允许不得转载,或转载时需注明出处:豫章小站 » IIS去除无用的HTTP响应头,屏蔽返回的Header中的IIS版本信息
分享到: 更多 (0)

评论 抢沙发


  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

智慧源于勤奋,伟大出自平凡

没有所谓的捷径,一切都是时间最平凡的累积,今天所做的努力都是在为明天积蓄力量

联系我们赞助我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏