从单独的解决方案访问Web.Config [英] Accessing Web.Config from a separate solution
问题描述
谢谢
p>您可以将任何库的配置设置放在主web.config中。很简单!
连接字符串非常简单。只需将您的连接字符串添加到与库中的app.config中具有相同名称的 connectionstrings
部分即可完成!
< connectionStrings>
< add name =SitefinityconnectionString =你的连接字符串/>
< / connectionStrings>
要添加配置设置,请在Web配置的顶部找到 applicationSettings
部分,并添加您的部分的信息。注意:请确保将您的库的设置访问修饰符设置为公开。您可以在属性ui中执行此操作。
< sectionGroup name =applicationSettingstype =System.Configuration.ApplicationSettingsGroup, System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089>
< section name =Your.Assemblytype =System.Configuration.ClientSettingsSection,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/>
< / sectionGroup>
然后,添加 applicationSettings
下的部分。
< applicationSettings>
< Your.Assembly>
< setting name =TestSettingserializeAs =String>
< value>测试值< / value>
< / setting>
< /Your.Assembly>
< / applicationSettings>
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>
这篇关于从单独的解决方案访问Web.Config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!