读取webconfig里面的appSetting和connectionString

时间:2021-02-20 08:53:36
<appSettings>
<add key="SiteURL" value="http://moss2007:7000" />
<add key="WebURL" value="" />
</appSettings>

在页面读取:

 private string siteUrl = ConfigurationManager.AppSettings["SiteURL"];
<connectionStrings>
<!--<add name="LogDBConn" connectionString="Data Source=11.192.241.151;Initial Catalog=MOSS_Log;User ID=sa;Password=Password01!"/>-->
<add name="LogDBConn" connectionString="Data Source=moss2007;Integrated Security=True;Initial Catalog=MOSS_Log" />
</connectionStrings>

在页面读取:

string strLogDBConn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["LogDBConn"].ToString();