This question already has an answer here:

I have the following declaration of my config file in Web.config

<section name="MyConfigTool" type="ProjetReporting.Utilities.MyConfigTool" requirePermission="false" />
<MyConfigTool configSource="MyConfig.config" />

And here is MyConfig.config content

<MyConfigTool  DEFAULT_PASSWORD="qWvC8moKuXZXxPx4D2xXh"/>

Here my custom section Handler

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

    }

I call it here

 MyConfigTool mcf = ConfigurationManager.GetSection("MyConfigTool") as MyConfigTool;
        string test = mcf.DEFAULT_PASSWORD_IMPERSONNATION;

Related posts

Recent Viewed