使用 LINQ 查询 web.config
我认为 ASP.NET 配置文件的 API 已经出局了。 .NET 4 中有一个新的 System.Web.Configuration.WebConfigurationManager 类,但其构建方式与 System.Configuration.ConfigurationManager 相同。
我宁愿能够使用 LINQ 将运行配置的模型作为 XDocument 进行查询。
有没有办法获取配置模型并使用 System.Linq.Xml 解析其 XML?我可以简单地打开“~/Web.config”并将其内容解析到 XDocument 中吗?这是否准确?
I think the API for ASP.NET config files is way-outed. There's a new System.Web.Configuration.WebConfigurationManager class with .NET 4, but its built in the same mold as System.Configuration.ConfigurationManager.
I'd rather just be able to query the model of the running configuration as an XDocument using LINQ.
Is there a way to get the model of the configuration and parse its XML using System.Linq.Xml? Can I simply open "~/Web.config" and parse its content into an XDocument--will this be accurate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这不准确。
配置文件是分层工作的,也就是说,你有 machine.config 和 web.config...我什至还记得更多这些配置文件...
您提到的类可以非常透明地处理这种分层...也就是说,不需要您手动合并内容。
您可以将配置文件用作 Xml 文件,但不能说仅通过读取一个配置文件即可检索适用于您的应用程序的所有配置。
No, this is not accurate.
Configuration files work in layers, that is, you have machine.config, and web.config... I can even remember of more of these config files...
The classes you have mentioned can handle this layering quite transparently... that is, without requiring you to merge things manually.
You could use the config file as an Xml file, but you cannot say that you are retrieving all the configurations that apply to your application, just by reading one config file.