我排除了一些从我的应用程序发送邮件的 ipaddress。这里我在 web.config 文件中创建了自定义标签
<configSections>
<sectionGroup name="ExcludeIPAddressListSectionGroup">
<section name="IPAddressListSection" type="CustomConfigurationHandler.CustomConfiguration, CustomConfigurationHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowLocation="true" allowDefinition="Everywhere"/>
</sectionGroup>
</configSections>
<ExcludeIPAddressListSectionGroup>
<IPAddressListSection>
<ExcludedList1 Range="StartingIP=192.168.185.1; EndingIP=192.168.185.50" ></ExcludedList1>
<ExcludedList2 Range="StartingIP=192.168.185.51;EndingIP=192.168.185.51" ></ExcludedList2>
</IPAddressListSection>
</ExcludeIPAddressListSectionGroup>
我创建了 ExcludeIPAddressListSectionGroup 部分并给出了排除这些 ips 的范围
我正在像这样从 web.config 读取自定义标签
Hashtable config = (Hashtable)ConfigurationManager.GetSection("ExcludeIPAddressListSectionGroup/IPAddressListSection");
foreach (DictionaryEntry deKey in config)
{
Hashtable attribs = (Hashtable)deKey.Value;
foreach (DictionaryEntry deAttrib in attribs)
{
string range = deAttrib.Value.ToString();
string[] range_arr = range.Split(';');
foreach (string range_str in range_arr)
{
Response.Write(range_str+"<br>");
}
}
}
我需要格式化字符串并将startingip和ending ip传递给这个函数bool Between(long value, long left, long right)