zoukankan
html css js c++ java
Config文件的操作
public
class
NSection : ConfigurationSection
{
public
NSection()
{
}
[ConfigurationProperty(
"
id
"
)]
public
int
ID
{
get
{
return
(
int
)
this
[
"
id
"
]; }
set
{
this
[
"
id
"
]
=
value; }
}
[ConfigurationProperty(
"
name
"
)]
public
string
Name
{
get
{
return
this
[
"
name
"
].ToString(); }
set
{
this
[
"
name
"
]
=
value; }
}
public
override
string
ToString()
{
StringBuilder sb
=
new
StringBuilder();
sb.AppendFormat(
"
id = {0};name = {1}
"
, ID, Name);
return
sb.ToString();
}
}
添加
NSection section
=
new
NSection();
section.ID
=
1
;
section.Name
=
"
Test
"
;
Configuration config
=
WebConfigurationManager.OpenWebConfiguration(
"
~
"
);
config.Sections.Remove(
"
nSection
"
);
config.Sections.Add(
"
nSection
"
, section);
config.Save();
}
修改
Configuration config1
=
WebConfigurationManager.OpenWebConfiguration(
"
~
"
);
NSection section1
=
config1.GetSection(
"
nSection
"
)
as
NSection;
section1.ID
=
2
;
section1.Name
=
"
Test2
"
;
config1.Save();
查看
Configuration config
=
WebConfigurationManager.OpenWebConfiguration(
"
~
"
);
AppSettingsSection appSection
=
(AppSettingsSection)config.GetSection(
"
appSettings
"
);
string
[] Keys
=
appSection.Settings.AllKeys;
for
(
int
i
=
0
; i
<
Keys.Length; i
++
)
{
Response.Write(Keys[i]
+
"
:
"
+
appSection.Settings[Keys[i]].Value
+
"
<br>
"
);
}
ConnectionStringSettingsCollection connectionStrings
=
WebConfigurationManager.ConnectionStrings;
for
(
int
i
=
0
; i
<
connectionStrings.Count; i
++
)
{
Response.Write(
string
.Format(
"
Name:{0}:Conn{1}Pro{2}<br>
"
, connectionStrings[i].Name, connectionStrings[i].ConnectionString, connectionStrings[i].ProviderName));
}
//
删除appSettings节点中的元素
appSection.Settings.Remove(
"
addkey1
"
);
//
修改appSettings节点中的元素
appSection.Settings[
"
addkey2
"
].Value
=
"
Modify key2's value
"
;
config.Save();
<
appSettings
>
<
add key
=
"
ConfigPath
"
value
=
"
~/Config/
"
/>
<
add key
=
"
UploadSavePath
"
value
=
"
~/uploads/
"
/>
<
add key
=
"
EncryptMethod
"
value
=
"
1
"
/>
<
add key
=
"
AppTimeOut
"
value
=
"
0
"
/>
<
add key
=
"
CookieName
"
value
=
"
UserLogin
"
/>
<
add key
=
"
MultiDomainName
"
value
=
""
/>
<
add key
=
"
EnableDomains
"
value
=
""
/>
<
add key
=
"
staticFileExt
"
value
=
"
.aspx
"
/>
<
add key
=
"
EnableLog
"
value
=
"
true
"
/>
<
add key
=
"
addkey2
"
value
=
"
Modify key2's value
"
/>
</
appSettings
>
<
connectionStrings
>
<
add name
=
"
Default
"
providerName
=
"
SqlClient
"
connectionString
=
"
server=FENGYUN;uid=sa;pwd=110110;database=CMS;
"
/>
</
connectionStrings
>
查看全文
相关阅读:
C# 模拟浏览器请求
关于获取时间后,时间格式为几天前,几小时前格式转化
关于通用的C#后台获取前台页面的标签的正则表达式
关于getHTML()方法和getHtmlAjax()方法 GetHttpLength, 清除HTML标签
性能测试术语
聚合报告中90% Line涉及到百分位数的概念
使用Windows的cmd运行(或通过批处理启动)Python项目(多目录项目)提示找不到模块的解决办法
OSError: [WinError 6] 句柄无效的解决办法
python中日志输出重复的解决办法
截图方法get_screenshot_as_file()注意点
原文地址:https://www.cnblogs.com/tommyli/p/732328.html
最新文章
scrapy数据增量式爬取
scrapy提交关键字请求
关于scrapy里的中间件和请求传参
利用scrapy框架爬取动态加载的数据
利用scrapy爬取文件后并基于管道化的持久化存储
scrapy框架的简单使用
模拟登录爬取数据、线程池的使用
利用etree对象进行爬取数据(xpath函数)
使用requests模块简单获取数据
input输入框自动获取焦点
热门文章
给数组里面的数据添加一组新数据
关于倒计时的一些探讨
关于vue的域名重定向和404
关于FlexBox的布局
常用js方法整理(个人)
时间格式,只取日期,不取时间。 字段值为空时,默认给0
MVC中控制器当中需要绑定SelectList,也就是所谓的DropDownList
MVC在VIEW中动态控制htmlAttributes的方法
Web Service和WCF的到底有什么区别
.NET Framework 各个版本介绍
Copyright © 2011-2022 走看看