Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Sharing Config File Settings

Reply
 
Old 07-11-2009   #1 (permalink)
headware


 
 

Sharing Config File Settings

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

My System SpecsSystem Spec
Old 07-13-2009   #2 (permalink)
sloan


 
 

Re: Sharing Config File Settings

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>






"headware" <david.k.land@xxxxxx> wrote in message
news:54b6a037-ee59-4198-b227-cdf437236e36@xxxxxx
Quote:

>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

My System SpecsSystem Spec
Old 07-14-2009   #3 (permalink)
headware


 
 

Re: Sharing Config File Settings

On Jul 13, 10:33*am, "sloan" <sl...@xxxxxx> wrote:
Quote:

> 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>
>
> "headware" <david.k.l...@xxxxxx> wrote in message
>
> news:54b6a037-ee59-4198-b227-cdf437236e36@xxxxxx
>
Quote:

> >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.
>
Quote:

> > 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.
>
Quote:

> > 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?
>
Quote:

> > Thanks,
> > Dave
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
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
file sharing settings in vista Vista networking & sharing
what is the web.config file? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46