Web.config and app.config issues

K

kalyankp78

Hi,
I have a question about config files. I have the following in my
application..

1. ASP.NET web application with a web.config
2. C# class library (BL and DAL) with an App.config
3. Two windows Console Applications with their own App.Config.

Now I try to retrieve a value in the DAL using this code.

string str = ConfigurationSettings.AppSettings.Get("Value");

This code works fine when the windows applications are running. But
when the Webapplication is running and invokes an method in the Data
Access layer, the piece of code tries to refer to the Web.Config
instead of its own app.config even though it is in the DAL. Is there
any code that will tell DAL to refer to its own config file?

Can anyone tell me if I can do what i trying to do and if yes what
changes do I need to make to my code for it to work?.
I do need the app.config at the DAL level as there are some settings
common to both the windows as well as web application and that is the
best place to put it.


Help Please,
Thanks Kalyan
 
K

Kevin Spencer

An app.config file is called "app.config" because it is the configuration
file for an application, not for a class library. When you use a class
library in any application, web or otherwise, it will use the application
configuration file for that application, which is, in this case, the
web.config file.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
K

kalyankp78

Kevin, Neil thanks for your replies.
So I am now wondering if i have to modify my architecture a bit. Since
a class library cannot have an app.config (and my Business and Data
Access layers are class libraries), do I make them an console
application?.

Sorry i am new to using config files and what i need is to have a way
of letting the web and the windows components of the same application
to access certain common settings by way of the DAL.

Can you give me any suggestions on how I should organize the
components?.

Thanks
 
K

Kevin Spencer

You are misunderstanding. A class library does not need an app.config. It is
not an application. It is used in applications. Each application has its own
app.config (or web.config, which is an ASP.Net app.config file). This
enables each application to have its own configuration. When you use a class
library in an application, you put the configuration settings needed by the
class library into the app.config for that application. That way, the class
library is more flexible on a per-application basis.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top