All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL,Server,全局变量_[SQL,Server教程]
Asp.net文件上传操作_.net资料_编程技术
详细阐述PHP环境下如何将gbk编码转成utf8格式_[PHP教程]
visual c++中设备环境简介
利用Asp.net,Ajax异步获取xml文档内容_[Asp.Net教程]
自己写的一个asp.net的生成曲线图的过程_[Asp.Net教程]
DropDownList控件根据value值选中它_[Asp.Net教程]
如何在十天内学会php之第二天_php资料_编程技术
一个有关SQL Server连接的问题_[SQL Server教程]
关于ASP.NET,2.0的目录结构变化_[Asp.Net教程]
Reading number is top 10 pictures
Discharge accidentally Actresses by the breast1
这才叫绝色美女1
妹子最好别玩单反
30 beautiful school beauty3
PengLiYuan lady for the world health organization fight TB and AIDS goodwill ambassador
A resort photographed beautiful young woman change clothes process vomiting blood1
采访美女孙菲菲
乳娘帕梅拉安德森4
中国处女图鉴1
Sora aoi mirror memorial classics4
Download software ranking
Unix video tutorial9
功夫熊猫2(上集)
Jinling thirteen stock
Unix video tutorial2
美女写真2
电脑知识及技巧大合集
仙剑奇侠传98硬盘WINXP版
豪门浪荡史
WebService在.NET中的实战应用教学视频 → 第4集
仙剑奇侠传98版歌曲
delv published in(发表于) 2014/1/16 9:28:28 Edit(编辑)
ASP.Net下两种全局变量的设置和读取方法_[Asp.Net教程]

ASP.Net下两种全局变量的设置和读取方法_[Asp.Net教程]

ASP.Net下两种全局变量的设置和读取方法_[Asp.Net教程]

本文介绍两种ASP.Net项目中全局变量使用的方式。web.config文件 和 Gloab文件。以下分别说明:



方法一:web.config文件
——设置:
在web.config文件里添加关键字key是通过标记来实现的,但是appSettings标记通常放在.....标记外面。例:
复制XML代码保存代码














——读取:
要在代码中引用这些数据库连接字符串,需要先添加对System.ConFiguration名字空间的引用,在这个名字空间中含有ConfigurationSettings类,其静态方法ConfigurationSettings.AppSettings属性可获取web.config文件中节的设置,读到的值为string型。例如:
复制C#代码保存代码using System.Configuration;
string conn1 = ConfigurationSettings.AppSettings["connString1"];
string conn2 = ConfigurationSettings.AppSettings["connString2"];
SQLConnection myConn1 = new SQLConnection(conn1);
OleDbConnection myConn2 = new OleDbConnection(conn2);
在VS2005中, ConfigurationSettings.AppSettings 可以换成 ConfigurationManager.AppSettings


方法二:Gloab文件
——设置:
在Global文件里中添加
复制C#代码保存代码protected void Session_Start(Object sender, EventArgs e)
{
Session["sqlConnectionString"]
= "uid=Username;pwd=password;database=MyTest;server=Localhost;Connect Timeout=300";
}
——读取:
在代码中的应用:
复制C#代码保存代码String strConnection=Session["sqlConnectionString"].ToString();
sqlConnection_1=new SqlConnection(strConnection);
推荐使用第一种方式!比较灵活,哈哈哈


来源:阿良.NET







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.