Home All Groups Group Topic Archive Search About

Retrieving machine.config/web.config values ...

Author
8 Feb 2006 11:59 AM
Sunil.Dua
Hi All,


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 through code in C#.


Few experiment i done are here :-
I tried with


'(NameValueCollection)ConfigurationSettings.GetConfig
(SectionName);
When I try to run 'NameValueCollection httpRun =
(NameValueCollection)ConfigurationSettings.GetConfig
("system.web/httpRuntime");'
I get an Invalid cast exception.


Then i tried with


Hashtable config =
(Hashtable)ConfigurationSettings.GetConfig("customSection");
MessageBox.Show(config["Name"].ToString());


It is also not working.


Can you please suggest me some good and secure solution.  asap.


Thanks.

Author
8 Feb 2006 12:37 PM
Christopher Reed
You can only use ConfigurationSettings for that particular section.
Overall, however, the config files are really just XML files, so you can use
something XmlDocument to acquire the file and then using the associated Xml
methods to read the values from the config file.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

Show quoteHide quote
"Sunil.Dua" <sunilgc***@gmail.com> wrote in message
news:1139399966.777529.271260@g47g2000cwa.googlegroups.com...
> Hi All,
>
>
> 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 through code in C#.
>
>
> Few experiment i done are here :-
> I tried with
>
>
> '(NameValueCollection)ConfigurationSettings.GetConfig
> (SectionName);
> When I try to run 'NameValueCollection httpRun =
> (NameValueCollection)ConfigurationSettings.GetConfig
> ("system.web/httpRuntime");'
> I get an Invalid cast exception.
>
>
> Then i tried with
>
>
> Hashtable config =
> (Hashtable)ConfigurationSettings.GetConfig("customSection");
> MessageBox.Show(config["Name"].ToString());
>
>
> It is also not working.
>
>
> Can you please suggest me some good and secure solution.  asap.
>
>
> Thanks.
>