可以通过Firefox的Firebug插件,或者直接在Chrome**重点内容me浏览器中键入**Ctrl+J 来检查响应的头部信息。
不需要的信息有:
Server Microsoft-IIS/7.5
X-AspNetMvc-Version 3.0
X-AspNet-Version 4.0.303319
X-Powered-By ASP.NET
-
移除X-AspNet-Version
在 web.config 中加入该行代码。<system.web> <httpRuntime enableVersionHeader="false"/> ... -
移除X-AspNetMvc-Version
在 Global.asax.cs 文件中加入protected void Application_Start() { MvcHandler.DisableMvcResponseHeader = true; } -
移除或修改Server值
在工程中加入一个module 类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"); // 你可以在此设置 HttpContext.Current.Response.Headers.Set("Server", "CERN httpd"); } } }此外还需要在web config 做进一步设置
<system.webServer> <modules> <add name="CustomHeaderModule" type="StrongNamespace.HttpModules.CustomHeaderModule" /> -
移除或更改 X-Powered-By
打开 IIS 的管理控制台界面(IIS7 Managerment Console)-> HTTP Response Headers

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/187853.html原文链接:https://javaforall.net
