【问题标题】:Azure webrole excesive headersAzure Web 角色过多的标头
【发布时间】:2012-08-01 02:02:41
【问题描述】:

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

基本上,Azure 会发送 IIS 版本和 .net 版本作为标头的一部分。

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

【问题讨论】:

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


    【解决方案1】:

    这是我在大多数项目中用来隐藏这些标题的方法:

    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>
    

    【讨论】:

      【解决方案2】:

      如果您想要一个完整的解决方案来删除 Azure 上的所有多余标头,该解决方案也适用于 Cassini,而无需使用自定义 HttpModule,请参阅此处:

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

      【讨论】:

        【解决方案3】:

        Windows Azure Web 角色本质上是启用了 IIS 的 Windows Server 2008。因此,如果您想定制 IIS,您可以使用启动脚本并调用 appcmd 来更改您想要的设置(或以您通常使用的任何其他方式对其进行操作)。您的脚本将类似于:

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

        【讨论】:

        • 我还没有真正尝试过。我确信它会起作用,但@sandrino Di Mattia 的回答要简单得多
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-29
        • 2014-09-11
        相关资源
        最近更新 更多