这是关于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, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
这是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;
}
}
}
返回始终为null。我已经没想完了。任何帮助表示赞赏。
答案 0 :(得分:8)
如何切换斜线方向:
return ConfigurationManager.GetSection("HttpExceptionHandler/errorLog") as ErrorLogConfiguration;