HttpRuntimeConfig MaxRequestLength

B

bixbarton

Does anyone know how to obtain the MaxRequestLength easily?

I have found that if you do the following;

object getCon = HttpContext.GetAppConfig("system.web/httpRuntime")

Then look at getCon in debug, you can see the HttpRuntimeConfig object
with the MaxRequestLength in it, but you cannot cast the object to
HttpRuntimeConfig, so cannot programmatically get at the
MaxRequestLength 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.
 
B

bixbarton

Figured it out...

Int32 maxRequestLength = 0;
object untypedHttpRuntime =
System.Configuration.ConfigurationSettings.GetConfig("system.web/
httpRuntime");
if (untypedHttpRuntime != null)
{
Type type = untypedHttpRuntime.GetType();
FieldInfo maxRequestLengthField = type.GetField("_maxRequestLength",
(BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic));
if (maxRequestLengthField != null)
{
object result = maxRequestLengthField.GetValue(untypedHttpRuntime);
if (result != null)
{
maxRequestLength = Convert.ToInt32(result);
}
}
}
 

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top