Home All Groups Group Topic Archive Search About

How to reference web.config from class

Author
13 Apr 2006 8:55 PM
Tom
In my asp.net application, I have created a class for
global variables and functions, and I have placed
this in the app_code directory so it is available to all my pages.
That part has worked fine.
But now, I need to add a new funtion in this class which
needs to reference web.config. How do I get a reference
to web.config from this class?
In other words, all my aspx pages are hooked up to
web.config automatically, but not a class which I have
placed in /app_code.

TIA!!
Tom

Author
13 Apr 2006 9:11 PM
Michael Kolias
System.Configuration.ConfigurationManager.AppSettings("key_name")

Show quoteHide quote
"Tom" <T**@discussions.microsoft.com> wrote in message
news:6163E118-A8E4-4A57-ACD4-79A5F1B7822F@microsoft.com...
> In my asp.net application, I have created a class for
> global variables and functions, and I have placed
> this in the app_code directory so it is available to all my pages.
> That part has worked fine.
> But now, I need to add a new funtion in this class which
> needs to reference web.config. How do I get a reference
> to web.config from this class?
> In other words, all my aspx pages are hooked up to
> web.config automatically, but not a class which I have
> placed in /app_code.
>
> TIA!!
> Tom
Are all your drivers up to date? click for free checkup

Author
13 Apr 2006 11:40 PM
Trevor Braun
You'll also have to add a new project reference to System.Configuration or
you won't see the ConfigurationManager class.

Trevor

Show quoteHide quote
"Michael Kolias" <mi***@alspaconsulting.com> wrote in message
news:8vmdnbkMnq4OIKPZRVn-gA@speakeasy.net...
> System.Configuration.ConfigurationManager.AppSettings("key_name")
>
> "Tom" <T**@discussions.microsoft.com> wrote in message
> news:6163E118-A8E4-4A57-ACD4-79A5F1B7822F@microsoft.com...
>> In my asp.net application, I have created a class for
>> global variables and functions, and I have placed
>> this in the app_code directory so it is available to all my pages.
>> That part has worked fine.
>> But now, I need to add a new funtion in this class which
>> needs to reference web.config. How do I get a reference
>> to web.config from this class?
>> In other words, all my aspx pages are hooked up to
>> web.config automatically, but not a class which I have
>> placed in /app_code.
>>
>> TIA!!
>> Tom
>
>
Author
13 Apr 2006 11:53 PM
Chris Fulstow
If you're using .NET 2.0 then the preferred class for accessing web
configuration is the WebConfigurationManager class:
http://msdn2.microsoft.com/en-us/library/ms151430.aspx

HTH,
Chris

Bookmark and Share

Post Thread options