C# 读取web.config配置文件 读取连接字符串

1. <connectionStrings>
<add name="mysql" connectionString="localhost"
providerName="System.Data.SqlClient" />
</connectionStrings>

string s = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["mysql"].ToString();


2. <appSettings>
<add key="mongodb" value="MongoDB:localhost" />
</appSettings>

string s = System.Configuration.ConfigurationManager.AppSettings["mongodb"].ToString();

原文地址:https://www.cnblogs.com/mayyan/p/7810635.html