maxRequestLength for .Net 4.5.1 framework

[Originally posted by]: http://stackoverflow.com/questions/23327338/maxrequestlength-for-net-4-5-1-framework

If you are hosted in IIS, you need two settings:

  • maxRequestLength – for ASP.net (measured in KB)
  • maxAllowedContentLength – for IIS (measured in Bytes)

Sample config: (this is for 100MB upload limit)

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="102400" executionTimeout="3600" />
    </system.web>
</configuration>
<system.webServer>
    <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="104857600" />
      </requestFiltering>
   </security>
</system.webServer>

The smaller of the two will take precedence. For IIS, the default is 4MB.

Error handling

Both throws different exceptions.

  • maxRequestLength – Whenever a file exceeds this setting, you’ll get an Application_Error (standard ASP error)
  • maxAllowedContentLength – Whenever a file exceeds this setting, you’ll get IIS error.

The IIS error is harder to debug, so it is advisable that you set the maxAllowedContentLength larger. maxRequestLength is easier to catch since its at application level.

Sources:

shareedit
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s