How to remove X-AspNetMvc-Version from header response without touching source code file (Global.asax.cs)?

Viewed 6346

I need to disable the X-AspNetMvc-Version from the response header of a large number of applications. The server where the applications are hosted has just the content and config files Global.asax, web.config, app.config for the application and source code files (*.cs) reside with some other team.

I could only find the solution as adding MvcHandler.DisableMvcResponseHeader = true; to Global.asax.cs. Any alternative solution(s) that involves working with any config file(s)?

3 Answers

Unfortunately the only way is to use the following code in your Global.asax: MvcHandler.DisableMvcResponseHeader = true;

This is an old post but no marked answer. I was able to achieve this using the code below. In your global.asax.cs we can remove any header.

protected void Application_PreSendRequestHeaders()
{
   if (HttpContext.Current != null)
   {
       HttpContext.Current.Response.Headers.Remove("x-aspnet-version");                
   }
}
Related