关于配置节的问题

jjstar 2004-04-28 03:54:52

下面是帮助文件中的例子,我什么运行出错呢?怎么改呀?

<configSections>
<section name="sampleSection"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>

<sampleSection setting1="Value1" setting2="value two"
setting3="third value" />
///////////////////
using System;
using System.Collections;
using System.Configuration;

class MyConfigurationReader {

public void ReadMySettings() {
IDictionary sampleTable = (IDictionary)
ConfigurationSettings.GetConfig("sampleSection");
string value1 = (string)sampleTable["setting1"];
string value2 = (string)sampleTable["setting2"];
string value3 = (string)sampleTable["setting3"];
}
}






出错信息

Server Error in '/test' Application.
--------------------------------------------------------------------------------

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Exception creating section handler.

Source Error:


Line 4: <configSections>
Line 5: <section name="sampleSection"
Line 6: type="System.Configuration.SingleTagSectionHandler" />
Line 7: </configSections>
Line 8:


Source File: C:\Inetpub\wwwroot\test\web.config Line: 6


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
...全文
102 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gordenfl 2004-07-30
  • 打赏
  • 举报
回复
up
jjstar 2004-07-30
  • 打赏
  • 举报
回复
自己搞定了,
using System;
using System.Collections;
using System.Configuration;
using System.Xml;
using System.Collections.Specialized;
namespace ServiceSales.ClassLib
{
/// <summary>
/// CConfig 的摘要说明。
/// </summary>
public class CConfig : IConfigurationSectionHandler
{
public Object Create(Object parent, object configContext, XmlNode section)
{
NameValueCollection settings;
try
{
NameValueSectionHandler baseHandler = new NameValueSectionHandler();
settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
}
catch
{
settings = null;
}
return settings;
}
}
}
jjstar 2004-04-29
  • 打赏
  • 举报
回复
SingleTagSectionHandler是系统内置的,当然实现了IConfigurationSectionHandler接口
CMIC 2004-04-28
  • 打赏
  • 举报
回复
你的代码有两处错误:
1.配置节中type的
指定从配置文件中读取节的配置节处理程序类的名称,也就是说
MyConfigurationReader类 必须改成SingleTagSectionHandler而且命名空间必须是System.Configuration。
2.SingleTagSectionHandler必须实现IConfigurationSectionHandler接口。

jjstar 2004-04-28
  • 打赏
  • 举报
回复
我写了一个class,
实现了IConfigurationSectionHandler,
就OK了,
为什么系统内置的就不好用呢?
:(

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧