I would like to block a bot with IIS. With Apache you can add a command to your .htaccess file, as outlined here. How would I accomplish this with IIS 7.5?
Update
In addition to answer below, there are a total of approaches I discovered since posting this question:
- URL Scan option listed in the accepted answer.
- Define a Request Filtering rule (example below)
- Define a URL Rewriting rule (example below)
Request Filter Rule
<system.webServer>
<security>
<requestFiltering>
<filteringRules>
<filteringRule name="BlockSearchEngines" scanUrl="false" scanQueryString="false">
<scanHeaders>
<clear />
<add requestHeader="User-Agent" />
</scanHeaders>
<appliesTo>
<clear />
</appliesTo>
<denyStrings>
<clear />
<add string="YandexBot" />
</denyStrings>
</filteringRule>
</filteringRules>
</requestFiltering>
</security>
[...]
</system.webServer>
URL Rewriting rule
<rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="YandexBot" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="Get Lost." />
</rule>
For my last project I ended going with option 2 since it is security focused and based on the integrated URL Scan built into IIS 7.