8

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)?

0

3 Answers 3

7

Set enableVersionHeader to false in your web.config is an alternate, I would prefer the web.config change to a handler solution like you have, obviously, since you will not need to access global.asax.cs to make the change:

just copy this line into the web.config’s <system.web> section:

<httpRuntime enableVersionHeader="false" />

http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableversionheader(v=vs.110).aspx

http://madskristensen.net/post/Remove-the-X-AspNet-Version-header

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Brian, however the solution you talked of takes care of X-AspNet-Version while I need it for X-AspNetMvc-Version.
I see, sorry, it looks like you have the best and only solution for ASP.NET MVC: arturito.net/2011/10/21/…
That's not the right answer as stated by Chitra Belwal
6

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.