aiouluosi
My Blog
博客园
社区
首页
新随笔
联系
管理
订阅
随笔- 50 文章- 0 评论- 9
GetWebConfig
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
/**/
///
<summary>
///
GetWebConfig的摘要说明 Author:Ken
///
</summary>
public
class
GetWebConfig
{
public
GetWebConfig()
{
//
//
TODO: 在此处添加构造函数逻辑
//
}
//
A---网站根目录下的Web.config
//
public static string GetAppSettingsValue = ConfigurationManager.AppSettings["conn"];
//
VS 2003
//
public static string GetAppSettingsValue = ConfigurationSettings.AppSettings["conn"];
//
VS 2005
//
public static string GetConnectionString = ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString;
//
VS 2005
public
static
string
GetAppSettingsValueByKey(
string
key)
{
if
((ConfigurationSettings.AppSettings[key]
!=
null
)
&&
(ConfigurationSettings.AppSettings[key].ToString().Length
>
0
))
{
return
ConfigurationSettings.AppSettings[key].ToString();
}
return
null
;
}
//
B---网站指定路径下的Web.config
//
Configuration confStr = ConfigurationManager.OpenExeConfiguration(Server.MapPath("/system_dntd/Web.config"));
public
static
string
GetAppSettingsValueByKeyAndfilePath(
string
key,
string
filePath)
{
Configuration confStr
=
ConfigurationManager.OpenExeConfiguration(filePath);
AppSettingsSection myconnsec
=
confStr.AppSettings;
AppSettingsReader Reader
=
new
AppSettingsReader();
string
result
=
(
string
)Reader.GetValue(key, System.Type.GetType(
"
System.String
"
));
if
(result
!=
null
)
{
return
result;
}
return
null
;
}
public
static
string
GetConnectionStringByfilePath(
string
filePath)
{
Configuration confStr
=
ConfigurationManager.OpenExeConfiguration(filePath);
ConnectionStringsSection myconnsec
=
confStr.ConnectionStrings;
//
获取连接字符串配置节
ConnectionStringSettings mystr
=
myconnsec.ConnectionStrings[
0
];
//
获取第一个连接字符串 AppConnectionString
//
mystr.ConnectionString = "";
//
修改连接字符串
if
(mystr
!=
null
)
{
return
mystr.ConnectionString;
}
return
null
;
}
}
posted @ 2008-03-12 11:25
tianya
阅读(14)
评论(0)
编辑
收藏
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
闪存
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
相关文章:
添加 免责声明
相关链接:
最新IT新闻:
Mono 2.0 发布 Linux 上的 .NET 框架成熟了吗?
史上九大最强网络黑客
微软拟2010年推新版SQL 强化商业智能功能
GMail Labs 新功能 - 做数学题确认是否发出邮件
OpenOffice四处创造纪录 占有全球25%办公软件市场
<
2008年3月
>
日
一
二
三
四
五
六
24
25
26
27
28
29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
给我留言
查看留言
我参加的小组
每日一句英语
Web技术联盟
随笔档案
2008年7月 (1)
2008年6月 (2)
2008年5月 (2)
2008年4月 (3)
2008年3月 (2)
2008年2月 (1)
2008年1月 (2)
2007年11月 (1)
2007年9月 (1)
2007年8月 (12)
2007年7月 (7)
2007年6月 (16)
相册
photo1
Asp.Net学习
我的博友
day
Jesse
戏水
My Player
My Player
最新随笔
1. NBear_MSDTC(客户端分布式操作数据库设置)
2. 提交之后按地址栏地址跳转页面
3. js获取任意一处控件的对象
4. 解决大文件上传问题^_*
5. 一种实用的Xml新闻发布系统
6. 关于Url重写问题
7. 文件编码问题
8. sql2005 数据导入注意事项
9. 关于Js截取字符串
10. GetWebConfig
最新评论
阅读排行榜
1. AspNetPager的用法(962)
2. ViewState用法案例(901)
3. 相对路径和绝对路径(670)
4. 关于DropDownList的绑定(627)
5. 关于Js截取字符串(502)
评论排行榜
1. FreeTextBox用法(2)
2. Id值的跳转与数据须对应(1)
3. 相对路径和绝对路径(1)
4. 页面提示并跳转代码(1)
5. GridView的RowDataBound和DataGrid的ItemDataBound邦定后触发事件(1)