读取区块连接字符串设置值
读取<connectionStrings>区块连接字符串设置值
读取<appSettings>区块连接字符串设置值
读取<mailSettings>区块连接字符串设置值
string conn1 = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
Response.Write("LocalSqlServer连接字符串:" + conn1 + "<br>");
string conn2 = ConfigurationManager.ConnectionStrings["SQL2000"].ConnectionString;
Response.Write("SQL2000连接字符串:" + conn2+ "<br>");
string conn3 = ConfigurationManager.ConnectionStrings["SQLExpress"].ConnectionString;
Response.Write("SQLEXPRESS连接字符串:" + conn3 + "<br>");
Response.Write("LocalSqlServer连接字符串:" + conn1 + "<br>");
string conn2 = ConfigurationManager.ConnectionStrings["SQL2000"].ConnectionString;
Response.Write("SQL2000连接字符串:" + conn2+ "<br>");
string conn3 = ConfigurationManager.ConnectionStrings["SQLExpress"].ConnectionString;
Response.Write("SQLEXPRESS连接字符串:" + conn3 + "<br>");
读取<appSettings>区块连接字符串设置值
string txtCompany = ConfigurationManager.AppSettings["Company"];
Response.Write("公司名称:" + txtCompany + "<br>");
string txtServiceTel = ConfigurationManager.AppSettings["Service TEL"];
Response.Write("客服电话:" + ConfigurationManager.AppSettings["Service Tel"] + "<br>");
Response.Write("公司名称:" + txtCompany + "<br>");
string txtServiceTel = ConfigurationManager.AppSettings["Service TEL"];
Response.Write("客服电话:" + ConfigurationManager.AppSettings["Service Tel"] + "<br>");
读取<mailSettings>区块连接字符串设置值
//打开Request所在路径网站的Web.config文件
Configuration config = ConfigurationManager.OpenWebConfiguration(this.Request.ApplicationPath);
//取得Web.config中Mail设定区块
MailSettingsSectionGroup netSmtpMailSection = (MailSettingsSectionGroup)config.GetSectionGroup
("system.net/mailSettings");
//读取显示mailSettingsx设定相关值
Response.Write("Mail主机名称:" + netSmtpMailSection.Smtp.Network.Host + "<BR>");
Response.Write("Mail主机Port:" + netSmtpMailSection.Smtp.Network.Port + "<BR>");
Response.Write("Mail信息:" + netSmtpMailSection.Smtp.From + "<BR>");
//如果Mail的Authentication验证模式选择Basic,则可读取UserName及Password
//Response.Write("用户名:" + netSmtpMailSection.Smtp.Network.UserName + "<BR>");
//Response.Write("用户密码:" + netSmtpMailSection.Smtp.Network.Password + "<BR>");
Configuration config = ConfigurationManager.OpenWebConfiguration(this.Request.ApplicationPath);
//取得Web.config中Mail设定区块
MailSettingsSectionGroup netSmtpMailSection = (MailSettingsSectionGroup)config.GetSectionGroup
("system.net/mailSettings");
//读取显示mailSettingsx设定相关值
Response.Write("Mail主机名称:" + netSmtpMailSection.Smtp.Network.Host + "<BR>");
Response.Write("Mail主机Port:" + netSmtpMailSection.Smtp.Network.Port + "<BR>");
Response.Write("Mail信息:" + netSmtpMailSection.Smtp.From + "<BR>");
//如果Mail的Authentication验证模式选择Basic,则可读取UserName及Password
//Response.Write("用户名:" + netSmtpMailSection.Smtp.Network.UserName + "<BR>");
//Response.Write("用户密码:" + netSmtpMailSection.Smtp.Network.Password + "<BR>");
金戈铁马