本文介绍了在web.config文件中添加ipaddress列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用web.config文件中的ipaddress列表验证用户ipaddress.

我使用安全标签添加ipaddress列表,如下所示

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

<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>


现在,我要检查用户使用此列表输入的ipadddress.

有人可以提出一些想法吗?

在此先感谢您.


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

can any one suggest some ideas?

Thanks in advance.

推荐答案


Import System.Configuration


2.将配置数据读取为:


2. Read config data as:

string configIP1 = ConfigurationManager.AppSettings["ip1"];


3.验证用户输入为:


3. Validate with user input as:

string user_input = txtUserInput.txt
if(user_input.Equals(configIP1))
{
//Valid ip entered
}
{
//Invalid ip entered
}



希望这就是您要寻找的...

希望对您有帮助.

〜Amol



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

Hope this will help you.

~Amol


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




使用这个名称,我们可以检查IP地址.




with this name we can able to check ip address.


这篇关于在web.config文件中添加ipaddress列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:22