【发布时间】:2013-05-08 16:44:19
【问题描述】:
我正在我们的托管环境中设置一个新的网络服务器。这是一个只能由我们使用的新虚拟机,所以我可以用它做我想做的事(在合理范围内)。它在 Windows 2008 R2 上运行 IIS 7,系统上安装了 ASP.Net 4.0。
我很想强制服务器上的所有站点使用以下 system.webServer 设置,除非它们被明确覆盖,但将它们添加到 Framework config folders 中的 Machine.config or Web.config 文件中(均为 32 位和 64 位版本)似乎没有任何效果。
我试图强制的设置如下。我知道这些设置在单个站点的 Web.config 中可以正常工作(因为我已经从我自己配置的生产站点复制/粘贴了它们)并且我知道肯定安装了 IIS URL Rewrite Module 2。
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By"/>
</customHeaders>
</httpProtocol>
<staticContent>
<remove fileExtension=".air"/>
<remove fileExtension=".svg"/>
<remove fileExtension=".ttf"/>
<remove fileExtension=".otf"/>
<remove fileExtension=".woff"/>
<remove fileExtension=".eot"/>
<mimeMap fileExtension=".air" mimeType="application/vnd.adobe.air-application-installer-package+zip"/>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
<mimeMap fileExtension=".ttf" mimeType="application/x-font-truetype"/>
<mimeMap fileExtension=".otf" mimeType="application/x-font-opentype"/>
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff"/>
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject"/>
</staticContent>
<rewrite>
<outboundRules>
<rule name="Remove RESPONSE_Server">
<match serverVariable="RESPONSE_Server" pattern=".+"/>
<action type="Rewrite" value=""/>
</rule>
</outboundRules>
</rewrite>
</system.webServer>
这些设置应该意味着X-Powered-By: HTTP 标头不存在并且Server: 标头为空,但是当我对此进行测试时,我得到以下信息:
[12:35:56] owen@plum:~$ curl -I http://new.server.ip
HTTP/1.1 200 OK
Content-Length: 689
Content-Type: text/html
Last-Modified: Mon, 13 May 2013 15:11:24 GMT
Accept-Ranges: bytes
ETag: "2ce2122ec4fce1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Tue, 14 May 2013 11:36:16 GMT
我是否遗漏了一些明显的东西?难道只是system.webServer部分不能从这些默认配置文件中继承?
【问题讨论】:
-
试试 ALL_CAPS 吗? ServerVariables 一般都是大写的。
-
不,摘录不是问题,正如我在问题中提到的,这是我知道在其他地方工作的配置摘录。 (不,HTTP 中的标头不是 ALL_CAPS,只是当我们从 ASP 或 ASP.Net 访问它们时。)
标签: asp.net iis hosting machine.config