隐藏ASP.NET MVC的版本信息,使其不在HTTP Header中显示。
一、隐藏:X-AspNetMvc-Version
在Global.asax文件的Application_Start方法中添加:
MvcHandler.DisableMvcResponseHeader = true;
二、移除 Header 中的 Server
在Global.asax文件中添加:
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
var app = sender as HttpApplication;
if (app == null || app.Context == null)
{
return;
}
// 移除 Server
app.Context.Response.Headers.Remove("Server");
}
三、移除 X-Powered-By
在Web.config文件中添加: