您的位置:首页 > 其它

IIS7.5如何限制某UserAgent 禁止访问

2016-05-05 23:36 330 查看
参见
Blocking Bots Based on User-Agent http://moz.com/ugc/blocking-bots-based-on-useragent http://serverfault.com/questions/312262/how-to-block-null-blank-user-agents-in-iis-7-5
If request filtering can't handle this, you can try 'URL Rewrite' a free Add-On from Microsoft and pretty helpful anyways.

Create a rule like this:

<rule name="NoUserAgent" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="^$" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You did not present a User-Agent header which is required for this site" />
</rule>

During a quick test this worked for both an empty User-Agent and a missing one.

I'm using the regular expression '^$' which is only valid for an empty string.

You can also return a 404 or whatever else you want rather than a 403.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: