==========大家看过来一下一个web.config问题==============

SuperFC 2004-08-20 11:11:17
参照帮助中的例子做的,出错了一直找不到错在了哪里;

例子地址在Visual studio2003帮助中的:
Visual Studio .NET/.NET Framework/Configuration Section Settings/Declaring and Accessing Custom Configuration Sections
操作步骤如下:
1.新建一个web application
2.修改web.config文件如下:
在<Configuration>块下添加:
<configSections>
<section name="sampleSection"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>

<sampleSection setting1="Value1" setting2="value two"
setting3="third value" />
....
<configSections>

3. 然后在Page_Load事件中将例子的后台代码拷贝进去
private void Page_Load(object sender, System.EventArgs e)
{
IDictionary sampleTable = (IDictionary)
ConfigurationSettings.GetConfig("sampleSection");
string value1 = (string)sampleTable["setting1"];
string value2 = (string)sampleTable["setting2"];
string value3 = (string)sampleTable["setting3"];

}

4. 可是老是报一个这样的错误请大家帮忙看看这是为什么....查了很久没有查出来....55555

Error Information:
Configuration Error
Parser Error Message: Exception creating section handler.

Source Error:


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

十分疑问中...........

...全文
118 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
SuperFC 2004-08-21
  • 打赏
  • 举报
回复
感谢hubinasm(火星撞地球之闭关修炼) 和 showtimenow(景) 的帮助。问题已经解决了,
thx
hubinasm 2004-08-21
  • 打赏
  • 举报
回复
楼主注意你用的是系统的SingleTagSectionHandler!
hubinasm 2004-08-21
  • 打赏
  • 举报
回复
<section name="sampleSection"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>
改成:
<section name="sampleSection" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Version和PublicKeyToken的值可以从machine.config文件中相应的复制过来即可!
showtimenow 2004-08-21
  • 打赏
  • 举报
回复
你可以看一下

自定义配置节处理实现个性化web.config
http://blog.mvpcn.net/chagel/archive/2004/05/30/1876.aspx
showtimenow 2004-08-21
  • 打赏
  • 举报
回复
读取自定义配置节没有你想得那么简单
需要用自定义的IConfigurationSectionHandler接口类读取app.config中的配置。

要两步:
第一步,在自己的应用中定义一个类:
public class ActionConfigurationSectionHandler : IConfigurationSectionHandler即可,并且 重载
public object Create(object parent, object configContext, System.Xml.XmlNode section)方法。
二:配置好.config文件
例:
<configSections>
<section name="mySection"
type="Chagel.Configration.Settings, Configuration" />
</configSections>
<mySection>
<AppName> MyApplication</AppName>
</mySection>
以上声明了一个mySection元素,并在configSections中声明了该配置的处理程序类名为Chagel.Configration.Settings,Configuration为程序集名称。接下来我们可以通过一个实现System.Configuration.IConfigurationSectionHandler接口的类来处理该配置元素


读取
<!--Sample1.aspx-->
private void Page_Load(object sender, System.EventArgs e)
{
Data data;
data = ConfigurationSettings.GetConfig("mySection") as Data;
this.tbName.Text = data.AppName;
}
zhpsam109 2004-08-20
  • 打赏
  • 举报
回复
<configSections>
....
</configSections>
......
<configSections>

SuperFC 2004-08-20
  • 打赏
  • 举报
回复
更正一下最后一个</configSections>
为手误应该是配置文件的最终的关闭标记</configuration>

sorry,希望大家能够试试代码,操作步骤真的不多就只有两步,一步粘贴web.config代码,另一步拷贝后台代码至page_load,但是我不知道为什么会出现这样的错误..
SuperFC 2004-08-20
  • 打赏
  • 举报
回复
哦,看出来了,帖子上面最后一个</configSections>
是在粘贴代码的时候自己敲上去的,也就是代码中本身没有.
SuperFC 2004-08-20
  • 打赏
  • 举报
回复
楼上的不太明白你的意思
“多了一个
</configSections>”
在配置文件中,configSection我是开闭方式的设置的
<configSections>

<!-- configuration info -->
</configSections>

可告之改如何修改吗?
showtimenow 2004-08-20
  • 打赏
  • 举报
回复
多了一个
</configSections>

62,046

社区成员

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

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

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

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