Click here to Skip to main content
15,892,005 members
Articles / Web Development / ASP.NET

Using ASP.NET HTTP Modules to restrict access by IP address

Rate me:
Please Sign up or sign in to vote.
4.88/5 (24 votes)
14 Nov 2006CPOL2 min read 135.3K   1.7K   86  
Demonstrates how to restrict access to your ASP.NET website by IP address, using an HTTP Module.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HTTP module example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>HTTP module example</h1>
        <h2>Restricting by client IP address</h2>
        <h3>Restricted content</h3>
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum ultricies, urna et vestibulum luctus, lacus massa bibendum velit, ac tincidunt massa ante at nibh. Nam eros leo, semper eu, accumsan sed, adipiscing id, velit. Curabitur enim. Mauris commodo rutrum eros. Fusce sed diam. Maecenas et lorem et arcu tincidunt pulvinar. Praesent orci. Donec ante. Cras tortor justo, aliquet id, dignissim non, feugiat id, metus. In tellus diam, aliquet eu, volutpat nec, scelerisque in, libero. Aliquam tortor orci, imperdiet sed, pretium tristique, luctus id, nisl. Integer ac tellus. Proin tristique, purus id lacinia cursus, leo diam pulvinar purus, ac aliquet lectus libero quis orci. Quisque lectus nulla, ultricies vestibulum, bibendum eget, volutpat fringilla, felis. Pellentesque blandit mi eu metus.</p>
    </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
United Kingdom United Kingdom
Chris is an ASP.NET MVC tech lead and MCPD with over 12 years' commercial experience producing web-based solutions in a wide range of environments. For the past 8 years he has focused on Microsoft technologies, delivering to major clients in both the public and private sectors.

http://chrisfulstow.com/

Comments and Discussions