我有一個運行在Azure Web Roles中的網站。我在asafaweb.com網站上測試了這個網站,並得到了「過多的標題」警告。Azure webrole excessive headers
基本上天青送出IIS版本和.NET版本作爲報頭的一部分。
有很多關於如何在IIS中關閉這些標頭的信息,但是如何在Azure中關閉它們?
我有一個運行在Azure Web Roles中的網站。我在asafaweb.com網站上測試了這個網站,並得到了「過多的標題」警告。Azure webrole excessive headers
基本上天青送出IIS版本和.NET版本作爲報頭的一部分。
有很多關於如何在IIS中關閉這些標頭的信息,但是如何在Azure中關閉它們?
這是我在大多數項目中使用隱藏這些標題:
的Global.asax.cs(僅適用於MVC項目)
protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
}
自定義的HttpModule
public class RemoveHeadersHttpModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += OnPreSendRequestHeaders;
}
private void OnPreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("Server");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
}
public void Dispose()
{
}
}
的web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Server" />
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true">
. . .
<add name="RemoveHeadersHttpModule" type="MyNamespace.RemoveHeadersHttpModule"/>
</modules>
. . .
</system.webServer>
Windows Azure Web角色本質上是Windows Server 2008,啓用了IIS。所以,如果你想定製IIS,你可以使用一個啓動腳本並調用appcmd來改變你想要的設置(或者用你通常做的其他方式來操作)。您的腳本看起來像:
%windir%\system32\inetsrv\appcmd set ...
如果你想有一個完整的解決方案,以消除天青也與卡西尼工作沒有使用自定義的HttpModule所有過多的頭,在這裏看到:
Removing/Hiding/Disabling excessive HTTP response headers in Azure/IIS7 without UrlScan
我還沒有真正嘗試過。我相信它會起作用,但是@sandrino Di Mattia的回答要簡單得多 – Greg 2012-08-20 06:45:14