标签:
参见
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.
标签:
原文地址:http://www.cnblogs.com/youlechang123/p/5463832.html