Section personnalisé dans Web Config
Bonjour,
Je voudrais modifier le web config pour mettre des url.
J'ai suivi ce tuto https://www.codeproject.com/Articles...on-with-Nested qui me semblait bien et que j'ai adapter avec mes objets
Voici ce que ça donnne
Mon fichier de config
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<configSections>
<sectionGroup name ="ChorusProGroup">
<section name ="IdentificationChorus" type ="IserbaChorusAPI.Helpers.IdentifcationChorus, IserbaChorusAPI.Helpers "/>
<section name ="urlApiCollectionSection" type="IserbaChorusAPI.Helpers.UrlChorusConfigSections, , IserbaChorusAPI.Helpers" />
</sectionGroup>
</configSections>
<ChorusProGroup>
<IdentificationChorus login="TECH_000000000033108" pwd="monpwd"/>
<urlApiCollectionSection>
<urlApiCollection>
<chorusUrlApi id="0" url="transverses/recuperer/modedepot" name="Mode de depôt"/>
</urlApiCollection>
</urlApiCollectionSection>
</ChorusProGroup> |
Création d'une classe UrlChorusConfigSections
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public class UrlChorusConfigSections : ConfigurationSection
{
[ConfigurationProperty("urlApiCollection", IsKey =false, IsRequired = true)]
public UrlApiCollection Members
{
get
{
return base["urlApiCollection"] as UrlApiCollection;
}
set
{
base["urlApiCollection"] = value;
}
}
} |
Création d'une clase "UrlApiCollection"
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public class UrlApiCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new ChorusUrlApi();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((ChorusUrlApi)element).Id;
}
protected override string ElementName
{
get
{
return "chorusUrlApi";
}
}
protected override bool IsElementName(string elementName)
{
return !String.IsNullOrEmpty(elementName) && elementName == "chorusUrlApi";
}
public ChorusUrlApi this[int index]
{
get
{
return base.BaseGet(index) as ChorusUrlApi;
}
}
public new ChorusUrlApi this[string key]
{
get
{
return base.BaseGet(key) as ChorusUrlApi;
}
}
} |
Création d'une classe "ChorusUrlAPI"
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class ChorusUrlApi :ConfigurationElement
{
[ConfigurationProperty("id", IsKey = true)]
public string Id { get { return (string)this["id"]; } }
[ConfigurationProperty("url", IsKey = false)]
public string url { get { return (string)this["url"]; } }
[ConfigurationProperty("name", IsKey = false)]
public string name { get { return (string)this["name"]; } }
} |
Dans mon controller, je récupère les informations
Code:
var chorusAPISection = ConfigurationManager.GetSection("urlApiCollectionSection") as UrlChorusConfigSections;
Malheureusement "chorusAPISection " est toujours nul..... :(
Qu'est ce que je ne fait pas correctement....
Merci pour votre aide