.config配置文件自定义节点读取问题
<?xml version="1.0" encoding="utf-8" ?><configuration>
<configSections>
<section name="busiflus" type="System.Configuration.SingleTagSectionHandler"/>
<section name="network" type="System.Configuration.DictionarySectionHandler"/>
<section name="iplist" type="System.Configuration.DictionarySectionHandler"/>
</configSections>
<appSettings>
<add key="hostname" value="this is my name"/>
</appSettings>
<busi conn="data source=;uid=;pwd=;database" time="10" check="true"/>
<network time="2" check="true">
<iplist ip="192.0168.0.68" check="true"/>
<iplist ip="192.0168.0.69" check="true"/>
</network>
</configuration>
如上App.config配置文件中的自定义参数,定义方法有问题吗?我应该如何读取各个节点的属性(包括每个子节点)。
请大家指教指教,最好能贴住代码示例。 --------------------编程问答-------------------- 关注中…… --------------------编程问答-------------------- app.config 及 web.config 中 ConnectionString 的加密与解密
Yuxiang 著于2007-9-10 19:50:41
在基于.NET的应用程序中,普通保存“连接字符串(ConnectionString)”配置是不恰当的!因为任何人都可以看到你的用户ID(用户名),及其密码。在本文中,我希望能教你如何实现对它们进行加密及解密操作。
--------------------编程问答-------------------- 顶一个! --------------------编程问答-------------------- 你需要自己写一个类实现 IConfigurationSectionHandler 接口。
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
DocManagerConfiguration config = new DocManagerConfiguration();
NameValueCollection settings;
try
{
NameValueSectionHandler baseHandler = new NameValueSectionHandler();
settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
}
catch
{
settings = null;
}
if (settings != null)
{
Alogrim alogrimClass = new Alogrim(Alogrim.SymmProvEnum.RC2);
alogrimClass.IV = "DocManager";
alogrimClass.Key = "DocManager";
if (bool.Parse(settings["IsEncrypt"]))
{
if (ConfigurationManager.ConnectionStrings["DatabaseConnectionString"] != null)
config.DatabaseConnectionString = alogrimClass.Decrypting(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString);
config.DefaultNameSpace = alogrimClass.Decrypting((string)settings["DefaultNameSpace"]);
config.EnableDataAccessTrace = bool.Parse(alogrimClass.Decrypting((string)settings["EnableDataAccessTrace"]));
config.WebDAL = alogrimClass.Decrypting((string)settings["WebDAL"]);
}
else
{
if (ConfigurationManager.ConnectionStrings["DatabaseConnectionString"] != null)
config.DatabaseConnectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ToString();
if (settings["DatabaseType"] != null)
config.DatabaseType = settings["DatabaseType"];
if (settings["EnableDataAccessTrace"] != null)
config.EnableDataAccessTrace = bool.Parse(settings["EnableDataAccessTrace"]);
if (settings["WebDAL"] != null)
config.WebDAL = settings["WebDAL"];
}
}
return config;
}
#endregion
--------------------编程问答-------------------- 读出后转换成IDictionary就可以了
补充:.NET技术 , C#