Ninetiger blog

-- my reminder

How to hide Asp.net MVC version and the hosting server info

In the Global.asax.cs file:

  public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // remove MVC version from headers
            MvcHandler.DisableMvcResponseHeader = true;
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var app = sender as HttpApplication;

            //Security: Remove "Server" from headers
            app?.Context?.Response.Headers.Remove("Server");
        }
    }

Comments:

Back to top