Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to validate the user ipaddress with the list of ipaddress in web.config file .

I add list of ipaddress using security tag as follow
XML
<security>
      <ipsecurity allowunlisted="false">
        <!--blocks every one unless the ip address in list-->
        <clear />
        <add ipaddress="127.0.0.1" allowed="true" /> 
        <add ipaddress="192.168.78.0" subnetmask="255.255.255.0" allowed="true" />
        <add ipaddress="193.167.89.0" subnetmask="255.255.255.0" allowed="true" />
      </ipsecurity>
</security>

now I want to check ipadddress entered by user with this list.

can any one suggest some ideas?

Thanks in advance.
Posted
Updated 1-Oct-12 2:19am
v2

Have you read this: http://www.stokia.com/support/misc/web-config-ip-address-restriction.aspx[^]?

This settings is handled by IIS, thus if the user ip is blocked, your code will never got notified.
 
Share this answer
 
v3
1. Import library as:
C#
Import System.Configuration

2. Read config data as:
C#
string configIP1 = ConfigurationManager.AppSettings["ip1"];

3. Validate with user input as:
C#
string user_input = txtUserInput.txt
if(user_input.Equals(configIP1))
{
//Valid ip entered
}
{
//Invalid ip entered
}


I hope this is what you are looking for...

Hope this will help you.

~Amol
 
Share this answer
 
v2
Comments
iyalarasi 4-Oct-12 5:17am    
I am not using ip address in appsettings in web.config,and I can't give name attribute to security tag.
The IPSecurity tag will be work only if IIS manager Role Service is configuered like

http://www.iis.net/configreference/system.webserver/security/ipsecurity/add#006[^]

But we can't configure this for windows xp or any client machine.

It can be done only in windows server2008 and vista.

So we can add list of ip address as

XML
<appSettings>
    <add key="RestrictIPAddress" value="192.168.78.0 to 192.168.78.50,193.167.89.0 to 193.167.89.50"/>
  </appSettings>



with this name we can able to check ip address.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900