读取<connectionStrings>区块连接字符串设置值
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>");

读取<appSettings>区块连接字符串设置值
string txtCompany = ConfigurationManager.AppSettings["Company"];
        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>");

相关文章:

  • 2021-08-07
  • 2021-05-17
  • 2021-07-30
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2022-01-10
相关资源
相似解决方案