加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – ConfigurationManager.GetSection返回null以显示正确

发布时间:2020-12-16 06:35:48 所属栏目:asp.Net 来源:网络整理
导读:这是关于web.config文件 这是ConfigSection configSectionssectionGroup name="HttpExceptionHandler" section name="errorLog" type="System.Configuration.SingleTagSectionHandler,System,Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c56193
这是关于web.config文件

这是ConfigSection

<configSections>
<sectionGroup name="HttpExceptionHandler">
  <section name="errorLog" type="System.Configuration.SingleTagSectionHandler,System,Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" />
  <section name="errorMail" type="System.Configuration.SingleTagSectionHandler,PublicKeyToken=b77a5c561934e089" />
</sectionGroup>

这是SectionGroup:

<HttpExceptionHandler>
    <errorLog type="MI.Generic.HttpExceptionHandler.SqlErrorLog,MI.Generic.HttpExceptionHandler" dataSource="opentraderdevdev" initialCatalog="MiTraderError" />
</HttpExceptionHandler>

这是代码:

public class ErrorLogConfiguration : ConfigurationSection
{
    public static ErrorLogConfiguration GetConfig()
    {
        return ConfigurationManager.GetSection("HttpExceptionHandlererrorLog") as ErrorLogConfiguration;
    }

    [ConfigurationProperty("initialCatalog",IsRequired = true)]
    public string InitialCatalog
    {
        get
        {
            return this["initialCatalog"] as string;
        }
    }

    [ConfigurationProperty("dataSource",IsRequired = true)]
    public string DataSource
    {
        get
        {
            return this["dataSource"] as string;
        }
    }
}

返回始终为null.我已经没想完了.任何帮助赞赏.

解决方法

如何切换斜线方向:

return ConfigurationManager.GetSection("HttpExceptionHandler/errorLog") as ErrorLogConfiguration;

这是一个similar example from MSDN.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读