Azure webrole excesive标头

时间:2012-08-01 02:02:41

标签: security azure http-headers azure-web-roles

我有一个在Azure Web角色中运行的网站。我针对asafaweb.com对该网站进行了测试,并收到了“过度标题”警告。

asafaweb.com screenshot

Azure基本上将IIS版本和.net版本作为标题的一部分发送出去。

有很多关于如何在IIS中关闭这些标头的信息,但是如何在Azure中将其关闭?

3 个答案:

答案 0 :(得分:3)

这是我在大多数项目中使用的隐藏这些标题的内容:

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>

答案 1 :(得分:2)

如果您想要一个完整的解决方案来删除 Azure 上的所有过度标题,这些标题也可以在不使用自定义HttpModule的情况下与Cassini一起使用,请参阅此处:

Removing/Hiding/Disabling excessive HTTP response headers in Azure/IIS7 without UrlScan

答案 2 :(得分:1)

Windows Azure Web角色本质上是Windows Server 2008,启用了IIS。因此,如果您想要定制IIS,您可以使用启动脚本并调用appcmd来更改所需的设置(或以您通常采用的任何其他方式操作它)。您的脚本看起来像:

%windir%\system32\inetsrv\appcmd set ...