Sharing Config File Settings

  • Thread starter Thread starter headware
  • Start date Start date
H

headware

I have an ASP.NET application and I need to create a Windows service
that is related to it. I would like to share some of the configuration
file settings in Web.config between the two. There are configuration
items in the <appSettings>, <connectionStrings> and
<system.web><mailSettings></system.web> sections that I need to be
able to access in the Windows service.

I know that some parts of config files allow you to specify an outside
file as the source but <connectionStrings> and <systemweb> don't
appear to allow this.

I could just parse the Web.config file from the Windows service but
isn't there some built in support for this? Can you load an external
config file somehow?

Thanks,
Dave
 
One way.
"Push out" some of the settings to seperate files. And share the files
between projects.

Below is what I have in my asp.net project web.config file.
You can probably do the same in a winforms app or windows service.


<?xml version="1.0"?>

<configuration>


<appSettings file="CustomAppSettings.config">

</appSettings>

<connectionStrings configSource="ExternalConnectionStrings.config" />

</configuration>


===========================

**Contents of** ExternalConnectionStrings.config

<connectionStrings >


<add name="LocalDatabaseInstance"
connectionString="server=MyServer;database=MyDatabase;Integrated
Security=SSPI; Pooling=false; " providerName="System.Data.SqlClient"/>

</connectionStrings>


==========================
**Contents of** CustomAppSettings.config

<appSettings>

<add key="Key1" value="Value1" />
<add key="Key2" value="Value2" />

</appSettings>
 
One way.
"Push out" some of the settings to seperate files.  And share the files
between projects.

Below is what I have in my asp.net project web.config file.
You can probably do the same in a winforms app or windows service.

<?xml version="1.0"?>

<configuration>

<appSettings file="CustomAppSettings.config">

</appSettings>

<connectionStrings configSource="ExternalConnectionStrings.config" />

</configuration>

===========================

**Contents of** ExternalConnectionStrings.config

<connectionStrings >

<add name="LocalDatabaseInstance"
connectionString="server=MyServer;database=MyDatabase;Integrated
Security=SSPI; Pooling=false; " providerName="System.Data.SqlClient"/>

</connectionStrings>

==========================
**Contents of** CustomAppSettings.config

<appSettings>

 <add key="Key1" value="Value1" />
 <add key="Key2" value="Value2" />

</appSettings>

Thanks for the input. I'm not sure what the difference between the
"file" and "configSource" attributes are, but the <mailSettings>
element doesn't have either one. This solution will get me most of the
way there, I was just hoping that there was a more generic, complete
solution.

Dave
 
Back
Top