获取App.config文件的key的value
System.Configuration.ConfigurationManager.AppSettings["keyName"]
获取web.config文件的key的value
ConfigurationManager.AppSettings["keyName"];
获取web.config文件的connectString
ConfigurationManager.ConnectionStrings["connectName"].ConnectionString;
配置文件:
①App.Config
1 <?xml version="1.0"?> 2 <configuration> 3 <configSections> 4 <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 5 <section name="Quartz_TimerJob.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 6 </sectionGroup> 7 </configSections> 8 <appSettings> 9 <add key="keyName" value="key's Value" /> 10 <!-- 多个key value组合--> 11 </appSettings> 12 </configuration>
②Web.config
key value部分 同上,没多少差
connectString 部分如下
<connectionStrings> <add name="LGFZDataLayer.Properties.Settings.XXConnectionString" connectionString="Data Source=10.***.*.***;Initial Catalog=XX;User ID=sa;Password=12345678" providerName="System.Data.SqlClient" /> </connectionStrings>