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
>
查看全文
相关阅读:
小程序使用字体图标-阿里版
vue项目安装vux
JS日期相减得到天数
vue的Vuex
ES6的Promise
根据坐标拖动(简单)
JSP 第三周作业
JSP第二次作业(2)
第二次JSP作业
JSP 第一次作业
原文地址:https://www.cnblogs.com/tommyli/p/732328.html
最新文章
HTTP学习链接
好玩的Python项目,简单的机器学习换脸术
两栏布局
图片在容器内上下左右居中对齐
Iterm2 快捷操作
函数节流和防抖
四、什么是vuex
三、vue如何配置路由 、获取路由的参数、部分刷新页面、缓存页面
二、vue学习--父元素如何获取子元素的值,子元素如何获取父元素的值
一、vue:如何新建一个vue项目
热门文章
二、ionic如何使用外链
一、ionic 图片轮播问题
git中常见操作指令
八、angularjs 中 filter在controller中的使用--避免多次遍历
七、angularjs 倒计时
一、angularjs基础了解
vue的watch
vue的computed计算属性
小程序插件
小程序使用字体图标-其他版
Copyright © 2011-2022 走看看