Extracting settings from config file outside 'ConfigurationSettings.AppSettings'

G

Guest

HI there,

My machine.config contains the following setting.
<httpRuntime
executionTimeout="90"
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>

I want to extract the value for max request length.
I started using 'ConfigurationSettings.GetConfig
("system.web/httpRuntime")' which I thought should return
what I am after.

All code example I have seen use something along the lines
of '(NameValueCollection)ConfigurationSettings.GetConfig
(SectionName);
When I try to run 'NameValueCollection httpRun =
(NameValueCollection)ConfigurationSettings.GetConfig
("system.web/httpRuntime");'
I get an Invalid cast exception.

Running just 'ConfigurationSettings.GetConfig
("system.web/httpRuntime")' in the immediate window
returns the following:
ConfigurationSettings.GetConfig("system.web/httpRuntime")
{System.Web.Configuration.HttpRuntimeConfig}
System.Object:
{System.Web.Configuration.HttpRuntimeConfig}
DefaultExecutionTimeout: 90
DefaultMaxRequestLength: 4194304
DefaultMinFreeThreads: 8
DefaultMinLocalRequestFreeThreads: 4
DefaultAppRequestQueueLimit: 100
DefaultShutdownTimeout: 10
DefaultDelayNotificationTimeout: 5
_executionTimeout: 90
_maxRequestLength: 41943040
_useFullyQualifiedRedirectUrl: false
_minFreeThreads: 8
_minLocalRequestFreeThreads: 4
_appRequestQueueLimit: 100
_shutdownTimeout: 10
_delayNotificationTimeout: 5
ExecutionTimeout: 90
MaxRequestLength: 41943040
UseFullyQualifiedRedirectUrl: false
MinFreeThreads: 8
MinLocalRequestFreeThreads: 4
AppRequestQueueLimit: 100
ShutdownTimeout: 10
DelayNotificationTimeout: 5

So I tried to declare a variable of
type: 'System.Web.Configuration.HttpRuntimeConfig'
The compiler then throws an error saying
that 'System.Web.Configuration.HttpRuntimeConfig' its
access level.

May be I'm barking at the wrong tree and there is an
object somewhere that retruns the value I am after?
 
C

Chris Jackson

You can just load up the config file into an XML document (since it is plain
XML) and then GetElementsByTagName(httpRuntime), iterating through the
returned collection (which should only have one entry, unless you define
this elsewhere) and grab the attribute from the element. I have not heard of
a method to get at data in the system.web portion - although my lack of
knowledge does not mean it doesn't exist, I finally gave up and started
doing it manually.
 
F

fRED.

Thanks for the reply.

I would know haw to do what you are describing, but it
seems too complicated to ject get one value from a config
file....

Nice to know I'm not the only one having a problem with
something that seems quite basic.

Tanks.

Fred.
 
G

Guest

Here is another way to search through the web.config using System.Xml and XPat

Dim intTimeout As Intege
Dim myConfig As New System.Xml.XmlDocument(
myConfig.Load(HttpContext.Current.Server.MapPath("~/web.config")
Dim root As System.Xml.XmlElement = myConfig.DocumentElemen
Dim formsNode As System.Xml.XmlNode = root.SelectSingleNode("/configuration/system.web/authentication[translate(@mode,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='FORMS']/forms[@timeout]"
If Not formsNode Is Nothing AndAlso Not formsNode.Attributes("timeout") Is Nothing AndAlso IsNumeric(formsNode.Attributes("timeout").Value) The
intTimeout = CType(formsNode.Attributes("timeout").Value, Integer
End If
 

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,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top