Sunday, 8 February 2015

ASP.NET Tips #22 - Removing X-Powered-By ASP.Net and other version headers

Most likely you do not want these headers to be displayed in your responses:

  • Server Microsoft-IIS/7.5
  • X-AspNetMvc-Version 4.0
  • X-AspNet-Version 4.0.303319
  • X-Powered-By ASP.NET

Removing X-AspNet-Version, In web.config add this:

<system.web>
   <httpRuntime enableVersionHeader="false"/>
</system.web>

Removing X-AspNetMvc-Version, In global.asax.cs add this:

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

Removing or changing X-Powered-By, IIS 7.5 - You can also remove the X-Powered-By header by including these lines to the element in Web.config:

<system.webServer>
   <httpProtocol>
      <customHeaders>
         <clear />
         <remove name="X-Powered-By" />
      </customHeaders>
   </httpProtocol>
</system.webServer>

Removing Server, In global.asax.cs add this:

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

No comments :

Post a comment