Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I remove unwanted http headers Server, X-AspNet-Version and X-AspNetMvc-Version using global.asax?

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");
    }

-

like image 708
Kiran M Avatar asked Oct 19 '25 11:10

Kiran M


1 Answers

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;
}
like image 192
too_cool Avatar answered Oct 21 '25 15:10

too_cool