473,387 Members | 1,619 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,387 software developers and data experts.

web.config in a class


I need to access the web.config file in a class. I am now using the line:

rootWebConfig1 = WebConfigurationManager.OpenWebConfiguration("~")

to get a reference to the config file. The question is the correct way to
get the config file in classes. There is only one config file and it is in
the root of the web site. I do not want to use a path since the location of
the web site can change. The classes will be in the App_Code dir.

Thank you,

--
Jerry
Oct 6 '08 #1
5 1058
Your cide looks correct to me. You are using the tilde to indicate the root
directory, which is always relative to the site, so should work wherever you
put the code. What problem are you having with this?

Also, are you planning to read or write the web.config? Note that changes in
the web.config file will cause the Web server to restart, and will also
refresh the cache entries, which may cause problems in your application

HTH

"Jerry C" <je*****@nospam.nospamwrote in message
news:1D**********************************@microsof t.com...
>
I need to access the web.config file in a class. I am now using the line:

rootWebConfig1 = WebConfigurationManager.OpenWebConfiguration("~")

to get a reference to the config file. The question is the correct way to
get the config file in classes. There is only one config file and it is in
the root of the web site. I do not want to use a path since the location
of
the web site can change. The classes will be in the App_Code dir.

Thank you,

--
Jerry

Oct 6 '08 #2
Steve,

Thank you for you reply,
I am not having any problems with the code. I was checking the community to
see if I was using the correct code. This app started with framework 1 and I
run into old code. Just checking for the latest.

Thank you
--
Jerry
"Steve" wrote:
Your cide looks correct to me. You are using the tilde to indicate the root
directory, which is always relative to the site, so should work wherever you
put the code. What problem are you having with this?

Also, are you planning to read or write the web.config? Note that changes in
the web.config file will cause the Web server to restart, and will also
refresh the cache entries, which may cause problems in your application

HTH

"Jerry C" <je*****@nospam.nospamwrote in message
news:1D**********************************@microsof t.com...

I need to access the web.config file in a class. I am now using the line:

rootWebConfig1 = WebConfigurationManager.OpenWebConfiguration("~")

to get a reference to the config file. The question is the correct way to
get the config file in classes. There is only one config file and it is in
the root of the web site. I do not want to use a path since the location
of
the web site can change. The classes will be in the App_Code dir.

Thank you,

--
Jerry


Oct 6 '08 #3
Hi Jerry,

Yes your code is correct.

Regards,
Allen Chen
Microsoft Online Support
--------------------
| Thread-Topic: web.config in a class
| thread-index: Ackn+DHlonxjN67AShKQCxnenpaCCQ==
| From: =?Utf-8?B?SmVycnkgQw==?= <je*****@nospam.nospam>
| References: <1D**********************************@microsoft.co m>
<u4**************@TK2MSFTNGP05.phx.gbl>
| Subject: Re: web.config in a class
| Date: Mon, 6 Oct 2008 14:12:09 -0700
| Lines: 46
| Message-ID: <0A**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:77402
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steve,
|
| Thank you for you reply,
| I am not having any problems with the code. I was checking the community
to
| see if I was using the correct code. This app started with framework 1
and I
| run into old code. Just checking for the latest.
|
| Thank you
| --
| Jerry
|
|
| "Steve" wrote:
|
| Your cide looks correct to me. You are using the tilde to indicate the
root
| directory, which is always relative to the site, so should work
wherever you
| put the code. What problem are you having with this?
| >
| Also, are you planning to read or write the web.config? Note that
changes in
| the web.config file will cause the Web server to restart, and will also
| refresh the cache entries, which may cause problems in your application
| >
| HTH
| >
| "Jerry C" <je*****@nospam.nospamwrote in message
| news:1D**********************************@microsof t.com...
|
| I need to access the web.config file in a class. I am now using the
line:
|
| rootWebConfig1 = WebConfigurationManager.OpenWebConfiguration("~")
|
| to get a reference to the config file. The question is the correct
way to
| get the config file in classes. There is only one config file and it
is in
| the root of the web site. I do not want to use a path since the
location
| of
| the web site can change. The classes will be in the App_Code dir.
|
|
|
| Thank you,
|
| --
| Jerry
| >
| >
| >
|

Oct 7 '08 #4
Excellent. Working code is always easier to troubleshoot ;-)

"Jerry C" <je*****@nospam.nospamwrote in message
news:0A**********************************@microsof t.com...
Steve,

Thank you for you reply,
I am not having any problems with the code. I was checking the community
to
see if I was using the correct code. This app started with framework 1 and
I
run into old code. Just checking for the latest.

Thank you
--
Jerry
"Steve" wrote:
> Your cide looks correct to me. You are using the tilde to indicate the
root
directory, which is always relative to the site, so should work wherever
you
put the code. What problem are you having with this?

Also, are you planning to read or write the web.config? Note that changes
in
the web.config file will cause the Web server to restart, and will also
refresh the cache entries, which may cause problems in your application

HTH

"Jerry C" <je*****@nospam.nospamwrote in message
news:1D**********************************@microso ft.com...
>
I need to access the web.config file in a class. I am now using the
line:

rootWebConfig1 = WebConfigurationManager.OpenWebConfiguration("~")

to get a reference to the config file. The question is the correct way
to
get the config file in classes. There is only one config file and it is
in
the root of the web site. I do not want to use a path since the
location
of
the web site can change. The classes will be in the App_Code dir.

Thank you,

--
Jerry



Oct 7 '08 #5
In my class library projects I'm using the following code to access the
configuration file:

string myValue =
System.Configuration.ConfigurationManager.AppSetti ngs.Get("myEntry");

This code exists since the .NET 1.x times and still works. It has (IMO) one
advantage over your solution, which is that it also works when the class
library is used by a windows forms application.

--
Martin

"Jerry C" wrote:
>
I need to access the web.config file in a class. I am now using the line:

rootWebConfig1 = WebConfigurationManager.OpenWebConfiguration("~")

to get a reference to the config file. The question is the correct way to
get the config file in classes. There is only one config file and it is in
the root of the web site. I do not want to use a path since the location of
the web site can change. The classes will be in the App_Code dir.

Thank you,

--
Jerry
Oct 9 '08 #6

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

Similar topics

13
by: Maxim Khesin | last post by:
I want to have a config file with my python proggie, satisfying the following requirements: 1) support key->(value, default) 2) simple and intuitive to read and edit 3) easyly readable into a...
2
by: bmcelhany | last post by:
Hi all, I have a solution with 4 projects: a class library, a windows app, a windows service, and an installer project. The class library handles all communication with the database and its...
4
by: grs | last post by:
Can a class library have a app.config file. Reason for asking is that the microsoft application blocks all read from myApp.exe.config. How can you use the application blocks if you do not have an...
5
by: AAguiar | last post by:
I have an asp.net project where the code behind the aspx page calls a c# class which makes calls to a managed static C++ class. The C# class works fine when the asp net worker process starts, when...
16
by: Timm | last post by:
I'm trying to use ASP objects (basically formed and populated based on Web.Config settings) and I want to use them in a different non-asp program with minimal reprogramming. So, my question is how...
4
by: WT | last post by:
My web site is using a library created in a separate project. VS 2005 has created for it an App.config file. The library is included as a refernce in my web site. When I copied my web site to it's...
9
by: Dick | last post by:
Visual Studio saves lots of values in the project's app.config file (connection strings for datasets, My.settings, etc.), but as far as I can see, if the project is in the middle teir, these values...
3
by: Fernando Chilvarguer | last post by:
Hello! I created a Class Library project in VS2005. Then, using VS, I was able to add a connection string to the project settings, which automaticaly created an app.config file for me. If I try...
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...
21
by: FutureShock | last post by:
I have just recently started to use OOP for my web applications and am running into some head scratching issues. I wanted to have a separate file for all my configuration variables. Some of them...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.