我在Web.config中有以下配置文件声明
<section name="MyConfigTool" type="ProjetReporting.Utilities.MyConfigTool" requirePermission="false" />
<MyConfigTool configSource="MyConfig.config" />
这是MyConfig.config内容
<MyConfigTool DEFAULT_PASSWORD="qWvC8moKuXZXxPx4D2xXh"/>
这是我的自定义部分处理程序
namespace ProjetReporting.Utilities
{
public class MyConfigTool : ConfigurationSection
{
private static readonly MyConfigTool ConfigSection = ConfigurationManager.GetSection("MyConfigTool") as MyConfigTool;
[ConfigurationProperty("DEFAULT_PASSWORD", IsRequired = true)]
public string DEFAULT_PASSWORD_IMPERSONNATION
{
get
{
return this["DEFAULT_PASSWORD_IMPERSONNATION"] as string;
}
}
public string getPass()
{
return DEFAULT_PASSWORD_IMPERSONNATION;
}
}
我在这里叫它
MyConfigTool mcf = ConfigurationManager.GetSection("MyConfigTool") as MyConfigTool;
string test = mcf.DEFAULT_PASSWORD_IMPERSONNATION;