IIS 10:如何阻止来自 null 或空用户代理的请求?

IIS 10: How to block requests from null or empty user-agent?

我阅读了阻止 null/empty 用户代理请求 here 的解决方案,但我正在检查我们是否可以通过 web.config 阻止它。

我们收到大量未设置用户代理的请求。有没有其他方法可以阻止没有用户代理的请求?

通过在服务器上安装 URLRewrite 2.x,您可以将重写规则添加到 web.config(system.webServer 部分)。像这样。

<rewrite>
  <rules>
    <rule name="BlockEmpty" stopProcessing="true">
      <match url=".*"/><!-- Any url -->
      <conditions>
        <add input="{HTTP_USER_AGENT}" pattern="^$"/><!-- Empty -->
      </conditions>
      <action type="CustomResponse" statusCode="403" statusDescription="Forbidden"/>
    </rule>
  </rules>
</rewrite>