Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > web.config in a class

Reply
Thread Tools

web.config in a class

 
 
Jerry C
Guest
Posts: n/a
 
      10-06-2008

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
 
Reply With Quote
 
 
 
 
Steve
Guest
Posts: n/a
 
      10-06-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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



 
Reply With Quote
 
 
 
 
Jerry C
Guest
Posts: n/a
 
      10-06-2008
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > 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

>
>
>

 
Reply With Quote
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      10-07-2008
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==?= <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
| Subject: Re: web.config in a class
| Date: Mon, 6 Oct 2008 14:12:09 -0700
| Lines: 46
| Message-ID: <(E-Mail Removed)>
| 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" <(E-Mail Removed)> wrote in message
| > news:(E-Mail Removed)...
| > >
| > > 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
| >
| >
| >
|

 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      10-07-2008
Excellent. Working code is always easier to troubleshoot

"Jerry C" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >
>> > 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

>>
>>
>>



 
Reply With Quote
 
Martin Bischoff
Guest
Posts: n/a
 
      10-09-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Generic class literals - e.g,, Class<Map<String, Integer>>.class Purush Java 4 04-13-2005 08:40 PM
instanciate a class in a jar file with class.forname, while my main class is in another jar cyril Java 2 08-25-2004 06:55 AM



Advertisments