Try this instead:
protected void Application_PreSendRequestHeaders(object sender, EventArgs e) { HttpContext.Current.Response.Headers.Remove("Server"); HttpContext.Current.Response.Headers.Remove("X-AspNet-Version"); HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version"); }
Also, in Application_Start, call it with the following statement
PreSendRequestHeaders += Application_PreSendRequestHeaders;
To remove the X-AspNet version, in web.config find / create and add:
<system.web> <httpRuntime enableVersionHeader="false" /> ... </system.web>
To remove the X-AspNetMvc version, go to Global.asax, find / create an Application_Start event and add the line as follows:
protected void Application_Start() { MvcHandler.DisableMvcResponseHeader = true; }
To remove X-Powered-By, in web.config find / create and add:
<system.webServer> <httpProtocol> <customHeaders> <remove name="X-Powered-By" /> </customHeaders> </httpProtocol> ... </system.webServer>
You can force all requests to go through managed code by adding this to your webconfig:
<modules runAllManagedModulesForAllRequests="true">
Even static files and unused resources must obey your header rules.
Literature:
source share