Remove Header Info from Response in Asp.NET Web API 2

To solve this issue, there are few ways but I used these two;

Global.asax.cs

I added these lines to remove server and asp.net version in Application_EndRequest blocks.

protected void Application_EndRequest()
{
        Response.Headers.Remove("Server");
       Response.Headers.Remove("X-AspNet-Version");
}

Web.config

The other thing we wanted to remove was X-Powered-By header. I added these XML lines into the system.webServer section

<httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
      </customHeaders>
</httpProtocol>

That’s all 🙂