|
Recent
Articles |
ASP.NET: Maintain Scroll Position After Postbacks To maintain the scroll position after postbacks is important for larger web pages in order to let the user know exactly what is going on. It is good usability and something you would expect in modern web...
GZip Vs. Deflate - Compression And Performance After I wrote about a HTTP compression module in ASP.NET 2.0 one of my colleagues pointed out that the Deflate compression is faster than GZip.Because the HTTP compression module chooses GZip over...
App_Code: Why It's Better I remember when ASP.NET 2.0 beta 1 was released about 2 years ago and I eagerly tried it out. The first thing that struck me as strange was the new application folders like App_Code, App_Data, and App_Themes etc.
Refactoring Your ASP.NET Project One day at work i was refactoring my code as I do everyday, when it suddenly hit me that our ASP.NET projects were also refactored in a sense. For those of you who don't know what refactoring is, here's...
ASP.NET: Permanent Redirection The easiest way to make a redirection in ASP.NET is using Response.Redirect(url). What it actually does is, that it creates a response with the "302 (Object Moved)" status code and the target destination. It tells the browser that the requested page is temporarily moved...
Validating a URL with Regular Expressions I had to build web form that took user input from standard ASP.NET input controls. In one of the text boxes the user must enter a valid URL, so I had to make some validation logic.
Visual Studio 2005 - Publishing Web Site What's the purpose of site precompilation? As it turns out, improved performance is often brought as an evidence of the benefits of precompilation. While precompilation certainly saves users from the...
|
|
|
01.12.07
ASP.NET - Block IP Addresses From Your Site
By
Mads Kristensen
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
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/
|