web.config 自定义 ConfigurationSection 和不必要的冗长
除非我做错了什么,否则我应该使用 ConfigurationSection、ConfigurationElement 和 ConfigurationElementCollection 的方式将要求我像这样格式化我的配置部分:
<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>
如果我对格式有更多的发言权,我会更愿意。我想像这样格式化我的部分:
<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>
有没有一种方法可以获取配置部分的 XML 并自己阅读它?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以实现
System.Configuration.IConfigurationSectionHandler
并配置它:然后您将整个
section
作为XmlNode
并可以解析您的自定义架构。编辑:这已被弃用。这是一种新方法它。
You can implement
System.Configuration.IConfigurationSectionHandler
and configure it:Then you get your entire
section
asXmlNode
and can parse your custom schema.edit: this is deprecated. here is one new way to do it.
好吧,您可以这样做,例如:
然后从 configDoc 开始工作。
Well, you could do, for example:
and then work from
configDoc
.