Block referrer spam request on ASP.NET application

Block unwanted spam traffic from your wesbite

Recently I was checking my Google Analytics for this website I spotted some referrer urls that were completely unknown to me. When I tried to visit the url of the referrers I got a lot of commercial and pop-ups after few redirects.

It looked really suspicious, so I tried to find a little bit more about these.

 Ga Graph

I found out that these sources are actually coming from bots that are here only to collect some data for the various purposes and make a lot of traffic that in the end does not do you any good (most of the time they do not anything really bad though) by they are making unnecessary processing by your application which might couse some slower response in the end.

If you are using AdSense, you might get surprised that all of this traffic is not considered as organic and will be excluded from your payment calculations.

So I decided to somehow get rid of these bots. For sure this could be done directly on IIS, but in cases when you are using shared host and do not have full access to IIS, only option is to do something on the application level.

Luckily IIS 7 and above introduced web.server config tag where you can put these kind of settings.

<system.webServer>
<rewrite>
<rules>
<rule name="Block darodar" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_REFERER}" pattern="*.darodar.com" />
</conditions>
<action type="AbortRequest" />
</rule>
<rule name="Block simple-share-buttons" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_REFERER}" pattern="*.simple-share-buttons.com" />
</conditions>
<action type="AbortRequest" />
</rule>
<rule name="Block semalt" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
          <conditions>
            <add input="{HTTP_REFERER}" pattern="*.semalt.com" />
          </conditions>
          <action type="AbortRequest" />
        </rule>
        <rule name="Block 7makemoneyonline" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*" />
          <conditions>
            <add input="{HTTP_REFERER}" pattern="*.7makemoneyonline.com" />
          </conditions>
          <action type="AbortRequest" />
        </rule>
        <rule name="Block hulfingtonpost" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*" />
          <conditions>
            <add input="{HTTP_REFERER}" pattern="*.hulfingtonpost.com" />
          </conditions>
          <action type="AbortRequest" />
        </rule>
	  </rules>
	</rewrite>
</system.webServer>
    

Basically URL rewrite rules are filtering requests from spam sources. Attribute stopProcessing="true" tells http module to stop executing other rules if filter is hit and action tag with type="AbortAction" instructs http module to stop request.

Tis will cut unwanted requests before they reach your code.

References

Disclaimer

Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.


About the author

DEJAN STOJANOVIC

Dejan is a passionate Software Architect/Developer. He is highly experienced in .NET programming platform including ASP.NET MVC and WebApi. He likes working on new technologies and exciting challenging projects

CONNECT WITH DEJAN  Loginlinkedin Logintwitter Logingoogleplus Logingoogleplus

JavaScript

read more

SQL/T-SQL

read more

Umbraco CMS

read more

PowerShell

read more

Comments for this article