【问题标题】:How to read an Internal ConfigurationSection from Web.Config in ASP.NET如何从 ASP.NET 中的 Web.Config 读取内部配置节
【发布时间】:2012-01-02 19:52:09
【问题描述】:

我正在尝试读取 Microsoft 定义的 ConfigurationSection:

Microsoft.ApplicationServer.Caching.DataCacheClientSection

但类型是内部的,所以我无法以常规方式访问它。

var dataCacheClientSection = (DataCacheClientSection)ConfigurationManager.GetSection("dataCacheClient");

我知道我可以使用反射,但我还有其他选择吗?

【问题讨论】:

    标签: asp.net .net configuration appfabric configurationsection


    【解决方案1】:

    您可以将配置文件打开为 XmlDocument 并使用 XPath 读取您想要的任何内容。

    类似:

    var xmlDoc = new XmlDocument();
    xmlDoc.Load(Assembly.GetExecutingAssembly().Location + ".config");
    XmlNode setting = xmlDoc.SelectSingleNode("configuration/...");
    

    在 SelectSingleNode 中使用正确的 XPath

    【讨论】:

    • 谢谢。害怕它可能会归结为那个。
    猜你喜欢
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多