I've identified four unnecessary HTTP header elements that get transmitted with one of my ASP.NET MVC2 web sites. I wanted to remove these headers to improve security and reduce header size and thought that it would be easy to remove these HTTP headers from IIS7 in the same manner. It turned out that each of them had to be removed with a different technique.
This header is removed through the IIS Manager. You can remove it on a site by site basis or remove it for the server. If removed from the server then it's removed from all sites on that server. This is the approach I prefer.
- Bring up IIS Manager.
- Click on the server name in the left panel
- Under the IIS section in the server area you will see HTTP Response Headers, double click on this.
- Click on the line that says "X-Powered-By ASP.NET Local"
- In the Actions pane on the right click Remove.
This one is a bit more tricky to remove and needed some code to be added to the web site.
In the MasterPage.master code behind file in the Page_Load function I put the following:
To get rid of this one I had to edit the web.config file and set the enableVersionHeader attribute to false:
<httpRuntime enableVersionHeader="false" />
In the constructor for the Global class in the global.asax.cs file I set the static DisableMvcResponseHeader property of the MvcHandler class to true.
MvcHandler.DisableMvcResponseHeader = true;