您的位置:首页 > 编程语言 > ASP

(翻译) 怎样移除IIS 响应中的 Server, X-AspNet-Version, X-AspNetMvc-Version 和 X-Powered-By

2016-11-10 01:11 716 查看
可以通过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



原文:http://r2d2.cc/2011/10/21/how-to-remove-server-x-aspnet-version-x-aspnetmvc-version-and-x-powered-by-from-the-response-header-in-iis7/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐