Leggere dal web.config [v. 2.0]
Come recuperare la connection string memorizzata nel web.config in ASP.NET 2.0 in C#
o altri valori
XML: web.config
<connectionStrings>
<clear />
<add name="myData"
providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|myDB.MDF;Integrated Security=True;User Instance=True"
/>
</connectionStrings>
C#
//using System.Configuration;
ConnectionStringSettings csdb = ConfigurationManager.ConnectionStrings["myData"];
//System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myData"];
//SqlDbConnection cnn = new SqlConnection(csdb.ConnectionString);
C#
//using System.Configuration;
ConnectionStringSettings csdb = ConfigurationManager.ConnectionStrings["mySetting"];
//System.Web.Configuration.WebConfigurationManager.AppSettings["mySetting"];
//System.Web.Configuration.WebConfigurationManager.GetSection("system.web/authentication");
Nel .NET 2.0 System.Configuration.ConfigurationSettings.AppSettings è deprecato in favore di System.Configuration.ConfigurationManager.AppSettings