Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 MaxRequestLength Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
HttpRuntimeSection..::.MaxRequestLength Property

Gets or sets the maximum request size.

Namespace:  System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
<IntegerValidatorAttribute(MinValue := )> _
<ConfigurationPropertyAttribute("maxRequestLength", DefaultValue := )> _
Public Property MaxRequestLength As Integer
Visual Basic (Usage)
Dim instance As HttpRuntimeSection
Dim value As Integer

value = instance.MaxRequestLength

instance.MaxRequestLength = value
C#
[IntegerValidatorAttribute(MinValue = )]
[ConfigurationPropertyAttribute("maxRequestLength", DefaultValue = )]
public int MaxRequestLength { get; set; }
Visual C++
[IntegerValidatorAttribute(MinValue = )]
[ConfigurationPropertyAttribute(L"maxRequestLength", DefaultValue = )]
public:
property int MaxRequestLength {
    int get ();
    void set (int value);
}
JScript
public function get MaxRequestLength () : int
public function set MaxRequestLength (value : int)

Property Value

Type: System..::.Int32
The maximum request size in kilobytes. The default size is 4096 KB (4 MB).
ExceptionCondition
ConfigurationErrorsException

The selected value is less than RequestLengthDiskThreshold.

The MaxRequestLength property specifies the limit for the buffering threshold of the input stream. For example, this limit can be used to prevent denial of service attacks that are caused by users who post large files to the server.

The value assigned to this property should be greater or equal to value assigned to the RequestLengthDiskThreshold property.

TopicLocation
How to: Upload Files with the FileUpload Web Server ControlBuilding ASP .NET Web Applications
How to: Upload Files with the FileUpload Web Server ControlBuilding ASP .NET Web Applications
How to: Upload Files with the FileUpload Web Server ControlBuilding ASP .NET Web Applications in Visual Studio

The following example shows how to obtain the current MaxRequestLength property value.

Visual Basic
' Get the MaxRequestLength property value.
Response.Write("MaxRequestLength: " & _
  configSection.MaxRequestLength & "<br>")

' Set the MaxRequestLength property value to 2048 kilobytes.
configSection.MaxRequestLength = 2048

C#
// Get the MaxRequestLength property value.
Response.Write("MaxRequestLength: " +
  configSection.MaxRequestLength + "<br>");

// Set the MaxRequestLength property value to 2048 kilobytes.
configSection.MaxRequestLength = 2048;

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Community Content   What is Community Content?
Add new content RSS  Annotations
Obtaining ConfigSection      ahauptfleisch   |   Edit   |  
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")

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker