I have two solutions, one is a class library and the other is a web application, and I want to get the connection string from the web.config file to the class library as I am developing a custom membership provider. I am using Framework 4.0 and MS Visual Studio 2010.
Thanks
You can put the configuration settings for any library in the main web.config. It's easy!
Connection strings are especially easy. Just add your connection string to the connectionstrings
section with the same name it has in the library's app.config, and you're done!
<connectionStrings>
<add name="Sitefinity" connectionString="your connection string"/>
</connectionStrings>
To add configuration settings, at the top of your web config, find the applicationSettings
section, and add your section's info. Note: be sure to set your library's settings access modifier to "Public". You can do this in the Properties ui.
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Your.Assembly" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
Then, add the section under applicationSettings
.
<applicationSettings>
<Your.Assembly>
<setting name="TestSetting" serializeAs="String">
<value>a test value</value>
</setting>
</Your.Assembly>
</applicationSettings>