Azure API 应用程序删除标准服务器 header

标签 azure asp.net-web-api azure-api-apps

我使用 API 应用程序将 ASP.net WebApi 部署到 azure。为了检查神秘列表中的另一项最佳实践,我想从所有 HTTP 请求(x-powered-by、服务器、x-aspnet-version)中删除标准服务器 header 。我的 web.config 如下,按照建议的配置 here

如果将我的应用程序部署到 Azure Web App, header 将成功删除。但是,重复相同的部署到 Azure API 应用程序似乎不遵守标准 web.config 配置来执行此操作,并且上述 header 仍然存在于所有 http 请求中。

有谁知道这是否还不受支持,或者是否有其他方法可以做到这一点?我只能认为网关或其他设备不尊重删除。

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime enableVersionHeader="false"  />
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <security>
      <requestFiltering removeServerHeader ="true"></requestFiltering>
    </security>
    <httpProtocol>
      <customHeaders>
        <clear />
        <remove name="X-Powered-By"/>
      </customHeaders>
    </httpProtocol>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

最佳答案

我们正在调查此问题并将予以修复。同时,您可以转到网关的应用程序设置并修改其 web.config。步骤:

  1. 导航到 YOURGATEWAYNAME.scm.azurewebsites.net
  2. 导航至站点\wwwroot
  3. 滚动到 web.config 并单击左侧的编辑按钮。您将能够编辑此文件。

或者,如果您不使用任何 API 应用特定功能,则可以将 Web API 部署为 Web 应用。

关于Azure API 应用程序删除标准服务器 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33211347/

相关文章:

azure - 对 https ://login. microsoftonline.com/{{TenantID}}/oauth2/token 进行 HTTP POST 调用时,访问 token 中缺少声明类型角色

azure - Gitlab + Jenkins 与 Azure Active Directory 身份验证

c# - WebAPI 首次调用服务缓慢

c# - 使用 WebApi、ajax 上传文件

azure - 禁用 Azure 应用服务的外部 IP

c# - 如何获取身份提供商名称

node.js - 如何使用 AMQP 以 "PeekLock"模式从 Azure 服务总线队列获取消息?

c# - User.Identity.Name 被模拟后返回 null

azure - 与 GitHub 同步后,Azure API 应用程序中出现部署失败错误

rest - 在 Azure 中获取访问 token 时用户名或密码不正确