Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to remove x-aspnet-version from response header for 400 and 404 status codes

What I have tried:

I tried adding the below code in web.config file

<httpRuntime enableVersionHeader="false" />

I also added the below code in the Global.ascx.cs file

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


The above works fine for http status code 200. But does not work for 400 and 404 status codes. Please help me!
Posted
Updated 19-Aug-22 3:11am
v2
Comments
Richard MacCutchan 18-Aug-22 11:59am    
Check the Response content to make sure the strings match exactly.
jaganps 18-Aug-22 13:13pm    
Yes, the strings match exactly.

https://serverfault.com/a/151120/355165[^]

To turn off the X-AspNet-Version header, change your web.config file:
XML
<system.web>
  <httpRuntime enableVersionHeader="false" />
</system.web>

To turn off the X-AspNetMvc-Version header, add the following to Application_Start:
C#
MvcHandler.DisableMvcResponseHeader = true;

To turn off the X-PoweredBy header, change your web.config file:
XML
<system.webServer>
  <httpProtocol>
    <customHeaders>
      <remove name="X-Powered-By" />
    </customHeaders>
  </httpProtocol>
</system.webServer>
 
Share this answer
 
Hi Richard Deeming, I tried but it will not work. The solution for the problem is to follow the below link

Remove Unwanted HTTP Response Headers - Microsoft Tech Community[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900