O
Oriane
Hi there,
In a web service (A), I would like to read and modify a web site (B)
configuration file. My goal is only to modify the appSettings section.
In order to avoid mistakes, I would like not to have these settings in the
default web.config file but, say, in a "settings.config" file, located in
the webservice virtual directory.
On IIS6, my webservice A is a web application from the B web site. So, the A
source files are in a (virtual) subdirectory of the B source files
directory.
Does it seem possible ?
___________________________________________________________________________________________________
Now, for a start, I've tried to read the settings in the web.config file of
A:
<?xml version="1.0"?>
<Configuration>
<...>
<appSettings>
<add key="a" value="aaa"/>
</appSettings>
<connectionStrings>
<clear/>
<add name="Stibil" connectionString="Server=.\sql2008..."/>
</connectionStrings>
I use this code:
System.Configuration.Configuration rootWebConfig1 =
WebConfigurationManager.OpenWebConfiguration(null);
if (rootWebConfig1.AppSettings.Settings.Count > 0)
{
KeyValueConfigurationElement customSetting =
rootWebConfig1.AppSettings.Settings[param];
if (customSetting != null)
return customSetting.Value;
}
return "Nothing";
And the fact is that "rootWebConfig1.AppSettings.Settings.Count" returns
0...
However,
"rootWebConfig1.AppSettings.ConnectionStrings..ConnectionStrings.ConnectionStrings.Count"
is 1.
I can't see where is my mistake...
__________________________________________________________________________________________________
Now if I want to read a config file (in my web service or in my web site),
which is not the default "web.config" file, possibly located in a virtual
subdirectory, what parameter do I need in the "OpenWebConfiguration" method
?
Best regards
In a web service (A), I would like to read and modify a web site (B)
configuration file. My goal is only to modify the appSettings section.
In order to avoid mistakes, I would like not to have these settings in the
default web.config file but, say, in a "settings.config" file, located in
the webservice virtual directory.
On IIS6, my webservice A is a web application from the B web site. So, the A
source files are in a (virtual) subdirectory of the B source files
directory.
Does it seem possible ?
___________________________________________________________________________________________________
Now, for a start, I've tried to read the settings in the web.config file of
A:
<?xml version="1.0"?>
<Configuration>
<...>
<appSettings>
<add key="a" value="aaa"/>
</appSettings>
<connectionStrings>
<clear/>
<add name="Stibil" connectionString="Server=.\sql2008..."/>
</connectionStrings>
I use this code:
System.Configuration.Configuration rootWebConfig1 =
WebConfigurationManager.OpenWebConfiguration(null);
if (rootWebConfig1.AppSettings.Settings.Count > 0)
{
KeyValueConfigurationElement customSetting =
rootWebConfig1.AppSettings.Settings[param];
if (customSetting != null)
return customSetting.Value;
}
return "Nothing";
And the fact is that "rootWebConfig1.AppSettings.Settings.Count" returns
0...
However,
"rootWebConfig1.AppSettings.ConnectionStrings..ConnectionStrings.ConnectionStrings.Count"
is 1.
I can't see where is my mistake...
__________________________________________________________________________________________________
Now if I want to read a config file (in my web service or in my web site),
which is not the default "web.config" file, possibly located in a virtual
subdirectory, what parameter do I need in the "OpenWebConfiguration" method
?
Best regards