读取web.config 或者 app.config中自定义配置的值的属性,常用2种方法. 假设有如下配置: <appSettings> <add key="A" value="config with A"/> <add key="B" value="config with B"/> </appSettings> using System.Configuration;[A] 方法string strTest = ConfigurationSettings.AppSettings["A"]; // get A 's value[B] 方法AppSettingsReader appReader = new AppSettingsReader();string strTest = appReader.GetValue(strKey,typeof(string)).ToString();e.g.private string GetConfig(string strKey) { AppSettingsReader appReader = new AppSettingsReader(); string strReturn; try { strReturn = appReader.GetValue(strKey,typeof(string)).ToString(); } catch(Exception ex) { strReturn = ex.Message.ToString(); } finally { appReader = null; } return strReturn; } 转载于:https://www.cnblogs.com/lijia7436/archive/2008/07/29/1255407.html