I have used the following code shown below. This removes the headers but is this the right way to do it? Should I go for another approach as many posts suggest?
I have added this code and it removes the unwanted headers but I'm new to handling these headers. Want to know if this is how it is done.
protected void Application_PreSendRequestHeaders()
{
Response.Headers.Remove("Server");
Response.Headers.Remove("X-AspNet-Version");
Response.Headers.Remove("X-AspNetMvc-Version");
}
-
Don't see anything wrong with your approach except you are doing it at runtime where as this can be handled with the following too.
Add this to web.config to get rid of the X-AspNet-Version header:
<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>
To remove X-AspNetMvc-Version Add the following in the Application_Start
event on Global.asax.cs
protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With