[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 867
  • Last Modified:

Retrieving settings from web.config from code

Does anybody know if it's possible and how to programmatically retrieve settings from web.config other than appSettings and user defined config sections from a code-behind class?

What I'm looking for specifically, is a way to get the maxRequestLength property from the system.web/httpRuntime section:

<system.web>
    <httpRuntime
        executionTimeout="90"
        maxRequestLength="256"      
        useFullyQualifiedRedirectUrl="false"
        minFreeThreads="8"
        minLocalRequestFreeThreads="4"
        appRequestQueueLimit="100"
    />
</system.web>
0
klingzor
Asked:
klingzor
1 Solution
 
Maulik ModiCommented:
If you could not find class allowing direct access to this section, you can go for XML API by loading web.config file in XmlDocument and then using Xpath Queries...

XmlDocument doc=new XmlDocument ( Server.Mappath ( "web.config" ) );
XmlNode eleHttpRuntime = doc.selectSingleNode("//httpRuntime");
if ( eleHttpRuntime != null)
{
   //Read maxRequestLength:
    double maxReqLength =Double.Parse( eleHttpRuntime.Attributes[ "maxRequestLength" ].Value);
}

Hope it helps!!!
MaulikCE


0
 
klingzorAuthor Commented:
Hi maulikCE, thanks for answering.

...so there is no particular class in the API to retrieve that value then?
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now