How to delete IIS custom headers like X-Powered-By: ASP.NET from response?

后端 未结 7 1656
小鲜肉
小鲜肉 2021-02-01 13:19

In IIS 7.0 integrated mode after deleting all headers with Response.ClearHeaders() IIS would add some other headers like Server

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 13:43

    For IIS7+ integrated mode, eth0 has it: tag in web.config. Thanks for that. As for the "Server" header, if using MVC, you can simply add:

        protected void Application_PreSendRequestHeaders()
        {
            Response.Headers.Remove("Server");
        }
    

    to your MvcApplication class in Global.asax. Otherwise, you can simply add a custom Http Module, handling the PreSendRequestHeaders event, and do the same thing.

提交回复
热议问题