Tuesday, August 8, 2017

Removing X-Powered-By ASP.Net and other version headers

Removing X-AspNet-Version

In web.config add this:
<system.web>
<httpRuntime enableVersionHeader="false"/>


Removing X-AspNetMvc-Version

In Global.asax.cs add this line:

protected void Application_Start()
{
             MvcHandler.DisableMvcResponseHeader = true;
}

Removing or changing Server

In Global.asax.cs add this:

protected void Application_PreSendRequestHeaders()
{
           //Response.Headers.Remove("Server");
          Response.Headers.Set("Server","Server");
          Response.Headers.Remove("X-AspNet-Version"); //alternative to above solution
          Response.Headers.Remove("X-AspNetMvc-Version"); //alternative to above solution
}

Removing or changing X-Powered-By

IIS 7 - You can also remove the X-Powered-By header by including these lines to the element:






or manually go to IIS7 Management Console and open HTTP Response Headers