HttpRuntimeConfig MaxRequestLength

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bixbarton

    #1

    HttpRuntimeConfig MaxRequestLength

    Does anyone know how to obtain the MaxRequestLengt h easily?

    I have found that if you do the following;

    object getCon = HttpContext.Get AppConfig("syst em.web/httpRuntime")

    Then look at getCon in debug, you can see the HttpRuntimeConf ig object
    with the MaxRequestLengt h in it, but you cannot cast the object to
    HttpRuntimeConf ig, so cannot programmaticall y get at the
    MaxRequestLengt h property.

    Anyone have a clue about this?

    I'm using .NET 1.1 and C#

    I'm starting to think that opening the machine.config and parsing the
    XML is going to be the only way, however I also will need a way of
    querying .NET to get the path to machine.config to avoid hardcoding it.

  • bixbarton

    #2
    Re: HttpRuntimeConf ig MaxRequestLengt h

    Figured it out...

    Int32 maxRequestLengt h = 0;
    object untypedHttpRunt ime =
    System.Configur ation.Configura tionSettings.Ge tConfig("system .web/
    httpRuntime");
    if (untypedHttpRun time != null)
    {
    Type type = untypedHttpRunt ime.GetType();
    FieldInfo maxRequestLengt hField = type.GetField(" _maxRequestLeng th",
    (BindingFlags.I nstance | BindingFlags.Pu blic |
    BindingFlags.No nPublic));
    if (maxRequestLeng thField != null)
    {
    object result = maxRequestLengt hField.GetValue (untypedHttpRun time);
    if (result != null)
    {
    maxRequestLengt h = Convert.ToInt32 (result);
    }
    }
    }

    Comment

    Working...