Reputation: 34396
Unless I am doing something wrong, the way I am supposed to use ConfigurationSection, ConfigurationElement and ConfigurationElementCollection, would require me to format my configuration section like so:
<serviceAuthorization>
<credentials>
<login username="system" password="password" mode="include">
<services>
<service type="AxeFrog.Mobile.Service.Security.AuthenticationService, AxeFrog.Mobile.Service" />
<service type="AxeFrog.Mobile.Service.Security.AnotherService, AxeFrog.Mobile.Service" />
</services>
</login>
<login username="test" password="pass" mode="exclude" />
</credentials>
</serviceAuthorization>
I would much prefer if I had a bit more say in the format. I would like to format my section like this:
<serviceAuthorization>
<login username="system" password="password" mode="include">
<service type="AxeFrog.Mobile.Service.Security.AuthenticationService, AxeFrog.Mobile.Service" />
<service type="AxeFrog.Mobile.Service.Security.AnotherService, AxeFrog.Mobile.Service" />
</login>
<login username="test" password="pass" mode="exclude" />
</serviceAuthorization>
Is there a way I can get the XML of the configuration section and just read it myself?
Upvotes: 1
Views: 1018
Reputation: 74527
You can implement System.Configuration.IConfigurationSectionHandler
and configure it:
<section name="serviceAuthorization" type="[your-type]"/>
Then you get your entire section
as XmlNode
and can parse your custom schema.
edit: this is deprecated. here is one new way to do it.
Upvotes: 1
Reputation: 99355
Well, you could do, for example:
string docName=System.Web.HttpContext.Current.Server.MapPath("Web.config");
XmlDocument configDoc = new XmlDocument();
configDoc.Load(docName);
and then work from configDoc
.
Upvotes: 0