移除IIS默认的响应头

移除Server

借助IIS URL Rewrite Module,添加如下的重写规则:

<rewrite>
        <allowedServerVariables>
            <add name="REMOTE_ADDR" />
        </allowedServerVariables>            
        <outboundRules>
            <rule name="REMOVE_RESPONSE_SERVER">
                <match serverVariable="RESPONSE_SERVER" pattern=".*" />
                <action type="Rewrite" />
            </rule>
        </outboundRules>
</rewrite>

重写规则存放在C:\Windows\System32\inetsrv\config\applicationHost.config中。

Add this to your global.asax.cs:


protected void Application_PreSendRequestHeaders()
{
    Response.Headers.Remove("Server");
    Response.Headers.Remove("X-AspNet-Version");
    Response.Headers.Remove("X-AspNetMvc-Version");
}
 
posted @ 2016-01-28 16:46  T#S  阅读(367)  评论(0编辑  收藏  举报