会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
往事隨風
C#.NET
博客园
首页
联系
管理
订阅
如何在web.config中設置自己個性的tag.
在configuration的標籤下面建立configSections.如下:
<
configSections
>
<
section
name
="fuxuan"
type
="HibernateTest.ConfigurationHandler, HibernateTest"
/>
</
configSections
>
然後寫入fuxuan的Tag:
<
fuxuan
>
<
add
name
="test"
value
="this is a test"
></
add
>
</
fuxuan
>
最後實現代碼:
using
System;
using
System.Collections;
using
System.Configuration;
using
System.Xml;
namespace
HibernateTest
{
/**/
///
<summary>
///
Configuration 的摘要描述。
///
</summary>
public
class
Configurations
{
private
Hashtable m_MyRegionConfig
=
new
Hashtable();
public
Hashtable MyRegionConfig
{
get
{
return
m_MyRegionConfig;
}
}
public
static
Configurations GetConfig()
{
return
(Configurations)System.Configuration.ConfigurationSettings.GetConfig(
"
fuxuan
"
);
}
internal
void
LoadValuesFromConfigFile(XmlNode xn)
{
foreach
(XmlNode child
in
xn.ChildNodes)
{
m_MyRegionConfig.Add(child.Attributes[
"
name
"
].Value,child.Attributes[
"
value
"
].Value);
}
}
}
internal
class
ConfigurationHandler : IConfigurationSectionHandler
{
IConfigurationSectionHandler 成員
#region
IConfigurationSectionHandler 成員
public
object
Create(
object
parent,
object
configContext, XmlNode section)
{
Configurations config
=
new
Configurations();
config.LoadValuesFromConfigFile(section);
return
config;
}
#endregion
}
}
最後調用:
private
void
Page_Load(
object
sender, System.EventArgs e)
{
Response.Write(Configurations.GetConfig().MyRegionConfig[
"
test
"
].ToString());
}
posted @
2007-07-04 17:29
芙蓉客
阅读(
193
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告