Retrieving settings from web.config from code

Posted on 2005-04-08
Last Modified: 2010-05-19
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:

Question by:klingzor
    LVL 6

    Accepted Solution

    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!!!

    LVL 2

    Author Comment

    Hi maulikCE, thanks for answering. there is no particular class in the API to retrieve that value then?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now