移除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:WindowsSystem32inetsrvconfigapplicationHost.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");
}
 
原文地址:https://www.cnblogs.com/olartan/p/5166830.html