码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-05-06 00:17:21      阅读:857      评论:0      收藏:0      [点我收藏+]

标签:

参见
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.

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

标签:

原文地址:http://www.cnblogs.com/youlechang123/p/5463832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!