2012-12-21 18 views
6

ja stworzyliśmy sekcję konfiguracji niestandardowych jak poniżejNierozpoznany sekcja konfiguracji

<configSections> 
    </configSections> 
    <Tabs> 
    <Tab name="Dashboard" visibility="true" /> 
    <Tab name="VirtualMachineRequest" visibility="true" /> 
    <Tab name="SoftwareRequest" visibility="true" /> 
    </Tabs> 

Sekcja Konfiguracja niestandardowa Handler

namespace EDaaS.Web.Helper 
    { 
     public class CustomConfigurationHandler : ConfigurationSection 
     { 
      [ConfigurationProperty("visibility", DefaultValue = "true", IsRequired = false)] 
      public Boolean Visibility 
      { 
       get 
       { 
        return (Boolean)this["visibility"]; 
       } 
       set 
       { 
        this["visibility"] = value; 
       } 
      } 
     } 
    } 

Podczas pracy Nierozpoznany sekcję konfiguracji Tabs wyjątkiem rzucać aplikacji. Jak rozwiązać ten problem

+0

można pokazać Twoja konfiguracja grupy sekcji? – dove

+0

Jak to pokazać? – JEMI

+0

masz coś w ramach configSections dla kart? – dove

Odpowiedz

15

Musisz napisać configuration handler, aby przeanalizować tę sekcję niestandardową. A następnie zarejestrować ten niestandardowy obsługi w pliku konfiguracyjnym:

<configSections> 
    <section name="mySection" type="MyNamespace.MySection, MyAssembly" /> 
</configSections> 

<mySection> 
    <Tabs> 
     <Tab name="one" visibility="true"/> 
     <Tab name="two" visibility="true"/> 
    </Tabs> 
</mySection> 

Teraz określić odpowiednią sekcję config:

public class MySection : ConfigurationSection 
{ 
    [ConfigurationProperty("Tabs", Options = ConfigurationPropertyOptions.IsRequired)] 
    public TabsCollection Tabs 
    { 
     get 
     { 
      return (TabsCollection)this["Tabs"]; 
     } 
    } 
} 

[ConfigurationCollection(typeof(TabElement), AddItemName = "Tab")] 
public class TabsCollection : ConfigurationElementCollection 
{ 
    protected override ConfigurationElement CreateNewElement() 
    { 
     return new TabElement(); 
    } 

    protected override object GetElementKey(ConfigurationElement element) 
    { 
     if (element == null) 
     { 
      throw new ArgumentNullException("element"); 
     } 
     return ((TabElement)element).Name; 
    } 
} 

public class TabElement : ConfigurationElement 
{ 
    [ConfigurationProperty("name", IsRequired = true, IsKey = true)] 
    public string Name 
    { 
     get { return (string)base["name"]; } 
    } 

    [ConfigurationProperty("visibility")] 
    public bool Visibility 
    { 
     get { return (bool)base["visibility"]; } 
    } 
} 

i teraz można przejść do ustawień:

var mySection = (MySection)ConfigurationManager.GetSection("mySection"); 
+0

To nie jest wroking – JEMI

+0

i Dodałem sekcję w sekcji konfiguracji takiej jak ta JEMI

+0

Czy pojawia się błąd? –

Powiązane problemy