无法在web.config中定义多个部分

时间:2013-10-20 11:24:19

标签: c# .net

我想在section group中有多个部分,比如

 **<CredentialsGroup>
        <Credentials>

          <company name="Carolina" userid="abc" password="dd"></company>
          <file name="dfbf0f94-767e-4c71-b4ee-2dc05fb76e3c.csv" 
      url="https://e.brightree.net/Home/file.csv"></file>

         <company name="Asbury" userid="abc" password="dde"></company>
          <file name="dfbf0f94-767e-4c71-b4ee-2dc05fb76e3c.csv"
      url="https://e.brightree.net/Home/file.csv"></file>
        </Credentials>
    </CredentialsGroup>**

这是我的customconfig文件

**public class CredentialsSection: ConfigurationSection
    {
        [ConfigurationProperty("company",IsRequired=true)]

        public CompanyElement Company
        {
            get {

                return (CompanyElement)this["company"];            
            }

            set
            {
                this["company"] = value;
            }

        }


        [ConfigurationProperty("file",IsRequired=true)]

        public FileElement File
        {
            get
            {

                return (FileElement)this["file"];
            }

            set
            {
                this["file"] = value;
            }

        }


    }

   public class CompanyElement : ConfigurationElement
    { 
    [ConfigurationProperty("name",IsRequired=true)]

    public string Name
    {
        get {

            return (string)this["name"];
        }

        set
        {
            this["name"] = value;
        }

    }

    [ConfigurationProperty("userid", IsRequired = true)]

    public string UserId
    {
        get
        {

            return (string)this["userid"];
        }

        set
        {
            this["userid"] = value;
        }

    }

    [ConfigurationProperty("password", IsRequired = true)]

    public string Password
    {
        get
        {

            return (string)this["password"];
        }

        set
        {
            this["password"] = value;
        }

    }


    }

 public   class FileElement : ConfigurationElement
    {

        [ConfigurationProperty("name", IsRequired = true)]

        public string Name
        {
            get
            {

                return (string)this["name"];
            }

            set
            {
                this["name"] = value;
            }

        }

        [ConfigurationProperty("url",IsRequired=true)]

    public string Url
    {
    get
    {
    return (string)this["url"];
    }
        set {
            this["url"] = value;

        }

    }


    }**

公司和文件节点应该是兄弟姐妹,他们的选择将根据公司名称进行选择

ConfigurationManager.GetSection(“CredentialsGroup / Credentials / company ['name'] =”+ companyName);                请帮忙

0 个答案:

没有答案