iEntry 10th Anniversary RSS Newsletter Advertising
Visit Twellow.com
Text: Decrease Font Size Increase Font Size | Print Print Article | Share: Delicious Digg StumbleUpon Post to Twitter Post to Facebook
Friday, January 12, 2007

ASP.NET - Block IP Addresses from Your Site

Recently, one of my readers asked me how to block certain IP addresses from accessing his ASP.NET website.

It was a good question that could be answered in multiple correct ways.

My answer was a plug 'n play HttpModule that could be reused in any ASP.NET application.

When an IP address is blocked it stops the response and sends a "403 Forbidden" header.

Even though it's almost impossible to block someone from accessing your website, this is a simple way to make it much harder to do.

For the regular web users this is probably enough to keep them out.

Implementation

Download the IpBlockingModule.cs below and add it to the App_Code folder. Then add the following line to the <system.web> section of the web.config.

<httpModules>

<add type="IpBlockingModule" name="IpBlockingModule"/>

</httpModules>

Then add the IP addresses you want to block, separated by commas, to the appSettings in web.config.

<appSettings>

<add key="blockip" value="44.0.234.122, 23.4.9.231" />

</appSettings>

Download

IpBlockingModule.zip (0,76 KB)

Comments

Tag:

Add to Del.icio.us | Digg | Reddit | Furl

Bookmark WebProNews:

Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

About the author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

I wrote an IP banning

I wrote an IP banning program for ASP, it's free to download (no cost, no registration). Just did it for fun... also allows wildcards and banning by countries.

http://www.ontarioabandonedplaces.com/ipguardian

 

Excellent!

I can't wait to try this out (you wouldn't happen to have vb source for this would you???)

BTW, I love blogengine.net. I'm using it for my sons website.

Thanks for all the you do for the .net community!

PathDoc15

Publish A Comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
12 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
SEARCH
Popular WPN Business Resources












Subscribe to WebProNews


Send me relevant info