我的项目包括一个Web服务(WCF)和一个在其他项目中使用公共库的控制台应用程序。 该库具有ApplicationSettings。 使用控制台应用程序,我只需要设置:
<?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="MyProject.Library.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
[...]
<applicationSettings>
<MyProject.Library.Properties.Settings>
<setting name="EnvironmentMask" serializeAs="String">
<value>RCT_</value>
</setting>
</MyProject.Library.Properties.Settings>
</applicationSettings>
[...]
</configuration>
我尝试做同样的一面Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="MyCompany.ConfigurationGroup">
<section name="SignedFileConfiguration" type="MyCompany.Web.SecureFileProxy.SignedFileConfigurationHandler, Net.MyCompany.Web" />
</sectionGroup>
<sectionGroup name="applicationSettings">
<section name="MyProject.Library.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
[...]
<MyCompany.ConfigurationGroup>
<SignedFileConfiguration Secret="SecretKey!" PatternOfGeneratedUrl="http://www.myCompany.net/cgi/getFile.aspx?volume={0}&path={1}&token={2}&name={3}" ConfiguratorType="MyCompany.Web.SecureFileProxy.SignedFileConfiguration, Net.MyCompany.Web">
<Volumes>
<add Name="fallow" PhysicalPath="" />
</Volumes>
</SignedFileConfiguration>
</MyCompany.ConfigurationGroup>
<applicationSettings>
<MyProject.Library.Properties.Settings>
<setting name="EnvironmentMask" serializeAs="String">
<value>DEV_</value>
</setting>
</MyProject.Library.Properties.Settings>
</applicationSettings>
[...]
</configuration>
在执行Web服务期间,我收到一个异常:System.Configuration.SettingsPropertyNotFoundException和对象MyProject.Library.Properties.Settings为空
唯一一个谈论它的网站是https://littletalk.wordpress.com/2008/05/07/use-applicationsettings-in-web-application/,但它并不适合我。
我希望你能帮助我。 感谢您的关注 此致
答案 0 :(得分:0)