Section config return对象引用未设置为对象的实例

时间:2015-03-26 21:39:04

标签: c# asp.net asp.net-mvc nullreferenceexception

我在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;

0 个答案:

没有答案