[Mono-list] Reading application settings from web.config file
Andrus Moor
kobruleht2 at hot.ee
Fri Jun 5 14:08:53 EDT 2009
I have VS generated web.config file which contains application settings:
<?xml version="1.0"?>
<configuration>
<configSections>
...
<applicationSettings>
<MyApp.Service.Properties.Settings>
<setting name="Server" serializeAs="String">
<value>myserver.com</value>
</setting>
</MyApp.Service.Properties.Settings>
</applicationSettings>
</configuration>
I need to get Server value in main web application asmx web service.
Under asp.net
Properties.Settings.Default.Server
returns correct value. Under mono 2.4 + mod_mono it returns
Server property default value as specified in VS generated code.
How to obtain Server value from web.config in Mono ?
I need also to get Server property value from an assembly called by this
asmx web service.
I tried code below but got exception
web.config does not contain appsettings
I verifed that rootWebConfig1.FilePath points to correct file web.config
file.
How to read application setting from application root web.config file from
child assembly ?
Andrus.
public string Server
{
get
{
System.Configuration.Configuration rootWebConfig1 =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
// rootWebConfig1.FilePath points to correct file.
if (0 < rootWebConfig1.AppSettings.Settings.Count)
{
System.Configuration.KeyValueConfigurationElement
customSetting =
rootWebConfig1.AppSettings.Settings["Server"];
if (null != customSetting)
return customSetting.Value;
else
throw new ArgumentException("No Server application
string");
}
throw new ArgumentException("web.config does not contain
appsettings");
}}
web.config contents:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions"
type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting"
type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler"
type="System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices"
type="System.Web.Configuration.ScriptingWebServicesSectionGroup,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization"
type="System.Web.Configuration.ScriptingJsonSerializationSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="Everywhere"/>
<section name="profileService"
type="System.Web.Configuration.ScriptingProfileServiceSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="MachineToApplication"/>
<section name="authenticationService"
type="System.Web.Configuration.ScriptingAuthenticationServiceSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="MachineToApplication"/>
<section name="roleService"
type="System.Web.Configuration.ScriptingRoleServiceSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" requirePermission="false"
allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Eeva.Service.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
...
<applicationSettings>
<setting name="Server" serializeAs="String">
<value>localhost</value>
</setting>
</MyApp.Service.Properties.Settings>
</applicationSettings>
</configuration>
More information about the Mono-list
mailing list