I have tried all of the following ways below to remove the 'X-AspNetMvc-Version' header but it still appears? (X-AspNetMvc-Version: 5.2)
IIS doesn't have any headers added. Could there be something else that is conflicting with the header causing it to still be shown?
Any help is much appreciated. Thanks in advance.
web.config
<httpRuntime requestValidationMode="2.0" enableVersionHeader="false" targetFramework="4.5" maxRequestLength="1048576" />
Global.asax.cs - (attempt 1)
MvcHandler.DisableMvcResponseHeader = true;
Global.asax.cs - (attempt 2)
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
}
Global.asax.cs - (attempt 3)
protected void Application_BeginRequest(object sender, EventArgs e)
{
var application = sender as HttpApplication;
if (application != null && application.Context != null)
{
application.Context.Response.Headers.Remove("X-AspNetMvc-Version");
}
}
Here is the full Global.asax.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
namespace website
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
MvcHandler.DisableMvcResponseHeader = true;
}
}
}