473,385 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Web.config and app.config issues

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

Apr 4 '06 #1
4 5007
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.

<ka********@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
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

Apr 4 '06 #2
this explains how to use a config file in your library, different from
web.config:

http://www.bearcanyon.com/dotnet/#AssemblySettings

cheers

neil

Apr 4 '06 #3
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

Apr 4 '06 #4
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.

<ka********@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
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

Apr 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Ryan | last post by:
I've created a custom configuration section that inherits (naturally) from System.Configuration.ConfigurationSection. The configuration section is working 99% fine, however I keep coming across a...
1
by: Matt F | last post by:
Two of the projects in my solution that both need to use a common user.config file. This is a data application - the executable that is created with the first project is the primary executable...
3
by: Brad | last post by:
Probably a very basic questions here: When using code to look at a web.config item, how can I tell if the value is/is not inherited? I have some common code that needs to iterate through settings...
6
by: TS | last post by:
I cannot get this to work. I added an app.config to a project i reference from my web application project (vs 05) but can see no way to access the settings within it. the other thing is that I...
3
by: SevDer | last post by:
Hi All, I am recently experiencing a weird problem. I don't know what exactly is the cause of the problem but here is my scenario and symptoms. First of all here is my architecture 1. I have...
3
by: =?Utf-8?B?RHVrZSAoQU4yNDcp?= | last post by:
I've added a web deployment project and want to use the config section replacement but I'm obviously not understanding something. I have set up an alternate appSettings file,...
1
by: =?Utf-8?B?Q2h1Y2sgUA==?= | last post by:
I have an asp.net solution with a web deployment project. When we try to build/debug, we get the message: An editor or project is attempting to check out a file that is modified in memory,...
10
by: =?Utf-8?B?TUNN?= | last post by:
When creating a new VB Web Application Project with VS2008, there are several settings (compiler settings, option strict, etc) that appear both in the web.config file and "My Project". I'm...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I cut and paste the following code from msdn help page which it just introduces view and multiview server controls. Here is what I do: in vs studio 2005, File --New Web Site, it...
5
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a app that uses several membership/role providers. I can list these Providers with the code: Dim rootWebConfig1 As Configuration rootWebConfig1 =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.