Reading from Web.config

T

TPS

What is the best way to read values from the web.config file.

I know how to read from the appSettings section, I want to read from other
sections like those listed below.

Thanks,
TPS
<customErrors mode="Off" defaultRedirect="/Pages/customerror.aspx"/>

<authentication mode="Forms">

<forms

slidingExpiration="true"

loginUrl="/pages/login.aspx"

name="dusacookie"

timeout="60"

path="/">

</forms>

</authentication>



<trace

enabled="false"

requestLimit="10"

pageOutput="true"

traceMode="SortByTime"

localOnly="true"

/>
 
K

Karl

You can create your own sections via configurationHandlers, you can read up
on this at:
http://openmymind.net/Configuration/index.html

However, I think what you are saying is you want to read the application
values from the web.config. A lot of those are read into objects you can
access. For example you can type Page.Trace.TraceMode to get the mode
specified in web.config

You can use Session.SessionMode/TimeOut

You can also get some from Context.IsCustomErrorEnabled

As you can see, they are read into a veriaty of objects...and I'm not sure
all the information is available. You might need to simply read it as an
XML document and parse it....

Not sure why you'd want this information anyways..

Karl
 
S

Steven Cheng[MSFT]

Thanks for Karl's good suggestions.

Hi TPS,

As for reading the settings in the web.conrfig I think Karl's suggestions
are quite reasonable. Also, there may be some scenarios that we can't read
web.config via those means, for example , in design-time .., then I think
we can just load the web.config as a normal xmlDocument and use the DOM
collection to retrieve any elements we want. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top