【发布时间】:2013-01-06 00:54:51
【问题描述】:
我的 ASP.NET 4.5 应用程序正在部署到共享主机,因此我无法访问 IIS 设置。要删除X-Powered-By 标头,我在web.config 中指定:
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
</system.webServer>
要删除Server 标头,我在Global.asax 中指定:
protected void Application_PreSendRequestHeaders(object sender, EventArgs e) {
HttpContext.Current.Response.Headers.Remove("Server");
}
但是,响应仍然包含两个标头:
Cache-Control:private
Content-Encoding:deflate
Content-Length:672
Content-Type:text/html; charset=utf-8
Date:Sun, 06 Jan 2013 00:41:20 GMT
Server:Microsoft-IIS/7.5
X-Powered-By:ARR/2.5
X-Powered-By:ASP.NET
如何删除它们?
【问题讨论】:
-
这不是 IIS 设置吗?
-
您可能需要编写一个自定义 HttpModule 来为您执行此操作 - 请参阅 this question
-
谢谢,我试试。但是
HttpModule不是和我在Global.asax中的方法一样吗? -
你绝对正确的伙伴,我浏览了你的那部分代码,看看我的回答
标签: asp.net iis web-config http-headers global-asax