gpt4 book ai didi

asp.net - ConfigurationManager.GetSection 返回 null 显然正确 'path'

转载 作者:行者123 更新时间:2023-12-02 18:29:27 25 4
gpt4 key购买 nike

这是关于 web.config 文件

这是配置部分

<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, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>

这是部分组:

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

代码如下:

public class ErrorLogConfiguration : ConfigurationSection
{
public static ErrorLogConfiguration GetConfig()
{
return ConfigurationManager.GetSection("HttpExceptionHandler\\errorLog") 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;
}
}
}

返回值始终为空。我已经没有主意了。任何帮助表示赞赏。

最佳答案

切换斜线方向怎么样:

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

这是一个similar example from MSDN .

关于asp.net - ConfigurationManager.GetSection 返回 null 显然正确 'path',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1945979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com