First, you do need to make sure that the ASP.NET method of limiting the request length (maxRequestLength) is greater than or equal to the IIS method of limiting the request length (maxAllowedContentLength).
So, if you want to restrict uploads to 10MB, set maxRequestLength to “10240” (or greater) and maxAllowedContentLength to "10485760".
Again, this essentially prevents the ASP.NET HTTP runtime from complaining about a request length that exceeds its limits, since the IIS feature will limit the length before ASP.NET has a chance to.
If the content exceeds the IIS value (maxAllowedContentLength), then the user will get a 404.13 error page.
In the web.config, you can add an override to this particular status and sub-status to tell IIS to redirect this particular status to a certain page.
This configuration block will prevent IIS from displaying it’s default (read: user unfriendly) error page for 404.13, and allow you to redirect them to a more useful page that informs them they’ve uploaded a file that is too large.
Be advised that the path attribute of error is an absolute path (you can’t reference the application root using ~) when the responseMode is set to "Redirect".
Finally, remember that maxRequestLength is in KB whereas maxAllowedContentLength is in bytes!
Putting all this together, your web.config file would look something like this:
<system.web>
<!-- maxRequestLength for asp.net, in KB -->
<httpRuntime maxRequestLength="10241" />
<customErrors mode="RemoteOnly" redirectMode="ResponseRedirect" defaultRedirect="~/ErrorPage.aspx"/>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" >
<remove statusCode="404" subStatusCode="13" />
<error statusCode="404" subStatusCode="13" prefixLanguageFilePath="" path="/mobile/ContentTooLarge.html" responseMode="Redirect" />
</httpErrors>
<security>
<requestFiltering>
<!-- maxAllowedContentLength, for IIS, in bytes -->
<requestLimits maxAllowedContentLength="10485760" />
</requestFiltering>
</security>
The above setting will set the maximum request length to 10MB.