Configuration config = WebConfigurationManager.OpenMachineConfiguration();HttpRuntimeSection configSection = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
// Get the MaxRequestLength property value.
Response.Write("MaxRequestLength: " +
configSection.MaxRequestLength + "<br>");
// Set the MaxRequestLength property value to 2048 kilobytes.
configSection.MaxRequestLength = 2048;
1. Open machine.config on the local machine.
WebConfigurationManager.OpenMachineConfiguration()
2. Open root web.config on the local machine.
WebConfigurationManager.OpenWebConfiguration(null)
3. Open web.config for the application at the root of the default web site.
WebConfigurationManager.OpenWebConfiguration("/")
4. Open web.config for a subdirectory of the application found at /MyApp.
WebConfigurationManager.OpenWebConfiguration("/MyApp/subdir")
5. Open web.config for an application at the root of another site.
WebConfigurationManager.OpenWebConfiguration("/", "Another Site")
6. Open the <location> tag for a subdirectory at the application level.
WebConfigurationManager.OpenWebConfiguration("/", null, "/subdir")
7. Open machine.config on another computer, using credentials provided.
WebConfigurationManager.OpenMachineConfiguration(null, "remotemachine", "user", "password")