Click here to Skip to main content
15,880,469 members
Articles / Programming Languages / C#

WCF Service Behavior Example: IPFilter - Allow/Deny Access by IP Address

Rate me:
Please Sign up or sign in to vote.
4.92/5 (17 votes)
15 Jun 2009CPOL7 min read 111.8K   2.3K   63  
WCF Service Behavior Example: IPFilter - Allow/Deny Access by IP Address
<?xml version="1.0" encoding="utf-8" ?>
<!-- Example configuration -->
<configuration>
  <configSections>
    <section name="IPFilter" type="IPFilter.Configuration.IPFilterConfiguration,IPFilter"/>
  </configSections>
  
  <IPFilter>
    <HttpModule FilterName="Default" />
    <Filters>
      <add Name="Default" DefaultBehavior="Deny">
        <deny hosts="192.168.11.12,192.168.1.*" />
        <allow hosts="192.168.0.0/16" />
        <deny hosts="*" />
      </add>
      
      <!-- A filter than only allows traffic from local network -->
      <add Name="LocalOnly">
        <allow hosts="10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.1/8" />
        <deny hosts="*" />
      </add>

      <!-- A filter than denies traffic from local network -->
      <add Name="DenyLocal">
        <deny hosts="10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.1/8" />
        <allow hosts="*" />
      </add>

      <!-- A filter than only allows traffic from loopback -->
      <add Name="LoopbackOnly">
        <allow hosts="127.0.0.1/8" />
        <deny hosts="*" />
      </add>

      <!-- A filter than denies traffic from loopback -->
      <add Name="DenyLoopback">
        <deny hosts="127.0.0.1/8" />
        <allow hosts="*" />
      </add> 
    </Filters>
  </IPFilter>
</configuration>

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions