读写ASP.NET web.config
2009-06-04 21:32
316 查看
如果你需要读写ASP.NET web.config. 请参考System.Web.Configuration.
在具体写代码以前,请先引用 System.Data, System.Collection,System.Web.Configuration,System.ComponetModule.
写入:
Configuration chapter = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
if (chapter != null)
{
AppSettingsSection cfgHandler = chapter.GetSection("appSettings") as AppSettingsSection;
ConfigHander handler = new ConfigHander();
handler.FirstName = "Gary";
handler.LastName = "Yang";
handler.SectionInformation.ForceSave = true;
cfgHandler.Settings.Add("Gary", "GaryYang");
chapter.Save();
}
如果你想以对象的形式添加到web.config中,你需要实现相对的类:
这其实是因为.Net Framework提供了IConfigurationSectionHandler接口.
public class ConfigHander : ConfigurationSection
{
[ConfigurationProperty("LastName", IsRequired = false, DefaultValue = "NotGiven")]
public string LastName
{
get {
return (string)base["LastName"];
}
set
{
base["LastName"] = value;
}
}
[ConfigurationProperty("FirstName", IsRequired = false, DefaultValue = "NotGiven")]
public string FirstName
{
get
{
return (string)base["FirstName"];
}
set
{
base["FirstName"] = value;
}
}
public ConfigHander()
{ }
}
更多资料: /article/5600186.html
自定义.NET应用程序配置节实例(WEB.CONFIG写自己的XML配置)!
http://www.cnblogs.com/xiazhi33/articles/945429.html
在具体写代码以前,请先引用 System.Data, System.Collection,System.Web.Configuration,System.ComponetModule.
写入:
Configuration chapter = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
if (chapter != null)
{
AppSettingsSection cfgHandler = chapter.GetSection("appSettings") as AppSettingsSection;
ConfigHander handler = new ConfigHander();
handler.FirstName = "Gary";
handler.LastName = "Yang";
handler.SectionInformation.ForceSave = true;
cfgHandler.Settings.Add("Gary", "GaryYang");
chapter.Save();
}
如果你想以对象的形式添加到web.config中,你需要实现相对的类:
这其实是因为.Net Framework提供了IConfigurationSectionHandler接口.
public class ConfigHander : ConfigurationSection
{
[ConfigurationProperty("LastName", IsRequired = false, DefaultValue = "NotGiven")]
public string LastName
{
get {
return (string)base["LastName"];
}
set
{
base["LastName"] = value;
}
}
[ConfigurationProperty("FirstName", IsRequired = false, DefaultValue = "NotGiven")]
public string FirstName
{
get
{
return (string)base["FirstName"];
}
set
{
base["FirstName"] = value;
}
}
public ConfigHander()
{ }
}
更多资料: /article/5600186.html
自定义.NET应用程序配置节实例(WEB.CONFIG写自己的XML配置)!
http://www.cnblogs.com/xiazhi33/articles/945429.html
相关文章推荐
- [转]ASP.NET Web.Config 读写辅助类
- ASP.NET Web.Config 读写辅助类
- ASP.NET Web.Config 读写辅助类
- asp.net 读写配置文件Web.Config
- ASP.NET Web.Config 读写辅助类
- asp.net 读写配置文件Web.Config
- Asp.net 中的web.config文件
- [GOOD Article] How to disable web.config Inheritance for Child Applications in Subfolders in ASP.NET?
- asp.net 读取web.config文件
- asp.net web.Config碰到的问题
- ASP.NET配置文件Web.config 详细解释
- Asp.Net修改上传文件大小限制(修改web.config)
- asp.net中web.config配置--log4net节点配置
- Asp.Net中的获取Web.config中设置的参数!(前后台的代码示例)
- ASP.NET web.config 设置
- 在Asp.net中,Web.Config中 membership 及 roleManager 的配置:
- ASP.NET web.config个节点详解
- Web.config详解+asp.net优化
- ASP.NET中使用web.config配置数据库连接
- Asp.Net 2.0加密Web.config配置文件