5

I've been getting "Connection forcibly closed" errors and in researching a resolution, I have seen suggestions to money with the following web.config options, which currently are not set in my web app.

Before I change them, I'd like to know what they are currently set to.

Can someone tell me how to read these values from .NET code, preferably VB.NET, though C# is fine.

<httpRuntime 
executionTimeout="90" 
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" 
minFreeThreads="8" 
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>
Chad
  • 23,658
  • 51
  • 191
  • 321

3 Answers3

8

Here is the MSDN Page that list what each value is and its default.

The following code will open the httpRuntime section programitcly

Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
object o = config.GetSection("system.web/httpRuntime");
HttpRuntimeSection section = o as HttpRuntimeSection;

This code was found here

And in VB

Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
Dim o As Object = config.GetSection("system.web/httpRuntime")
Dim section As HttpRuntimeSection = TryCast(o, HttpRuntimeSection)

Make sure you are using/Importing the following namespaces.

System.Configuration;
System.Web.Configuration;

Edit based on comment.

When calling WebConfigurationManager.OpenWebConfiguration From MSDN

path Type: System.String The virtual path to the configuration file. If null, the root Web.config file is opened.

Even if you do not have httpRuntime defined in your web.config it is the root Web.config, and that is returned. I have tested this with and without httpRuntime defined.

David Basarab
  • 72,212
  • 42
  • 129
  • 156
  • Hmm. This reads the web.config directly. My web.config and my machine.config do not have these sections in them, yet, I would expect that there are DEFAULT settings that I could query using the framework even though I chose not to override these default settings by adding the section in my web config. – Chad May 18 '10 at 16:15
  • 1
    @George see my edit. It will open the httpRuntime even if you do not have it defined in your web.config. – David Basarab May 18 '10 at 16:21
3

The MSDN documentation provides the meanings and defaults for this :)

If you're interested in other web.config values/meaning/defaults, start with the <configuration> schema and drill down to what you're after. For quick reference (.Net 4 values):

<httpRuntime 
   executionTimeout="110"
   maxRequestLength="4096"
   requestLengthDiskThreshold="80"
   useFullyQualifiedRedirectUrl="false"
   minFreeThreads="8"
   minLocalRequestFreeThreads="4"
   appRequestQueueLimit="5000"
   enableKernelOutputCache="true"
   enableVersionHeader="true"
   requireRootedSaveAsPath="true"
   enable="true"
   shutdownTimeout="90"
   delayNotificationTimeout="5"
   waitChangeNotification="0"
   maxWaitChangeNotification="0"
   requestPriority="Normal"
   enableHeaderChecking="true"
   sendCacheControlHeader="true"
   apartmentThreading="false"
/>
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
-1

The default values for a particular installation are stored in the machine.config file. To access these values you can use:

ConfigurationManager.OpenMachineConfiguration();

To get the configuration. There may be some security restrictions to access these values.

Keltex
  • 26,220
  • 11
  • 79
  • 111
  • Not my downvote - but actually, the documentation explicitly states: "The httpRuntime element is not explicitly defined in the Machine.config file or in the root Web.config file." – Nick Craver May 18 '10 at 16:06
  • 1
    It's not punishment - it's meant to mark a post as not useful. Since the post was incorrect it is not useful. – Mike Cole May 19 '10 at 16:37