IIS7移除响应头里边的服务器信息
1 X-AspNetMvc-Version
在Global.asax的Application_Start方法中加入
MvcHandler.DisableMvcResponseHeader = true;
2 X-AspNet-Version
web.config中
<httpRuntime enableVersionHeader="false" />
3 X-Powered-By
web.config中
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
4 Server
using System; using System.Web; namespace Project.Infrastructure.Web.Modules.Http { public class CustomHeaderModule : IHttpModule { public void Init(HttpApplication context) { context.PreSendRequestHeaders += OnPreSendRequestHeaders; } public void Dispose() { } void OnPreSendRequestHeaders(object sender, EventArgs e) { //HttpContext.Current.Response.Headers.Remove("Server"); // Or you can set something funny HttpContext.Current.Response.Headers.Set("Server", "CERN httpd"); } } }
在web.config添加以下配置
<system.webServer> <modules> <add name="CustomHeaderModule" type="StrongNamespace.HttpModules.CustomHeaderModule" />
最近评论