0
我有這樣的app.config:如何在app.config中添加自定義配置設置?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Me.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<connectionStrings>
<add name="MyConnectionString01" connectionString="...." />
<add name="MyConnectionString02" connectionString="...." />
</connectionStrings>
<applicationSettings>
<Me.Properties.Settings>
<setting name="BaseDatosMedioAcceso" serializeAs="String">
<value>SQLServerEF6</value>
</setting>
</Me.Properties.Settings>
</applicationSettings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup>
</configuration>
但我想補充這樣的設置:
<DataBases>
<add Description="Local" ConnectionString="MyConnectionString01"/>
<add Description="Local (Test)" ConnectionString="MyConnectionString02"/>
</DataBases>
但我不知道在哪裏恩把這個配置。我試圖創建一個配置節,但它不起作用。
這個想法是爲用戶提供一個易於閱讀的描述,並將該描述與連接字符串關聯以用於實體框架。
謝謝。
爲什麼如果我使用標籤「appSettigns」它的工作原理和當我使用標籤「DataBases」它不起作用? – 2014-11-08 15:23:27
Web.config文件必須僅包含用於覆蓋Machine.config文件中的設置的配置項的條目。一些額外的讀物可能會有所幫助:http://support.microsoft.com/kb/815179#3 | http://msdn.microsoft.com/en-us/library/ms960520(v=cs.70).aspx | http://msdn.microsoft.com/en-us/library/ms178685(v=vs.100).aspx – 2014-11-08 15:53:42