Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC are maxRequestLength and maxAllowedContentLength ignored in a subfolder web.config?

I have both maxRequestLength and maxAllowedContentLength set in web.config (20MB each) in a sub directory (i.e. Areas\Administration\Views). I have file uploading within administration and when I try to upload a large file (~9MB in this case) I get "Maximum request length exceeded". If I move the two settings to the root it works but I'd prefer not to do so. Any suggestions?

Technology: ASP.NET, .NET 4.0, MVC 3 and IIS 7 on Windows Server 2008 Enterprise.

Stack Trace:

[HttpException (0x80004005): Maximum request length exceeded.]
    System.Web.HttpRequest.GetEntireRawContent() +11472119
    System.Web.HttpRequest.GetMultipartContent() +232
    System.Web.HttpRequest.FillInFormCollection() +345
    System.Web.HttpRequest.get_Form() +157
    Microsoft.Web.Infrastructure.DynamicValidationHelper.<>c__DisplayClass12.<ReplaceCollection>b__e() +63
    Microsoft.Web.Infrastructure.DynamicValidationHelper.<>c__DisplayClass12.<ReplaceCollection>b__11() +20
    Microsoft.Web.Infrastructure.DynamicValidationHelper.DeferredCountArrayList.get_Count() +20
    System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, RequestValidationSource requestCollection) +34
    System.Web.HttpRequest.get_Form() +212
    System.Web.Mvc.HttpRequestExtensions.GetHttpMethodOverride(HttpRequestBase request) +160
    System.Web.Mvc.AcceptVerbsAttribute.IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) +55
    System.Linq.Enumerable.All(IEnumerable`1 source, Func`2 predicate) +149
    System.Web.Mvc.ActionMethodSelector.RunSelectionFilters(ControllerContext controllerContext, List`1 methodInfos) +428
    System.Web.Mvc.ReflectedControllerDescriptor.FindAction(ControllerContext controllerContext, String actionName) +140
    System.Web.Mvc.ControllerActionInvoker.FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, String actionName) +27
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +148
    System.Web.Mvc.Controller.ExecuteCore() +159
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
    System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
    System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
like image 294
Adam Schentag Avatar asked Dec 22 '11 15:12

Adam Schentag


People also ask

What is maxrequestlength and maxallowedcontentlength in ASP NET Core?

The MaxRequestLength property is used to set the maximum upload File Size Limit in older ASP.Net versions. But in ASP.Net Core, a new property, maxAllowedContentLength is used to increase the maximum upload File Size Limit. In this article I will explain with an example, how to set MaxRequestLength in ASP.Net Core.

How to limit the size of a file in MVC?

Create a new MVC web project and name it "ImgFileSizeLimit". You need to add/update the values of "executionTimeout", "maxRequestLength" & "maxAllowedContentLength" properties if not already added in the "Web.config" file, as shown below. .....

How to increase the maximum upload file size limit in ASP NET?

But in ASP.Net Core, a new property, maxAllowedContentLength is used to increase the maximum upload File Size Limit. In order to increase the maximum upload File Size Limit in ASP.Net Core, the upload File Size Limit needs to be set in the following two locations.

What is the maximum size of a HTTP request?

Http Runtime Section. Max Request Length Property System. Web. Configuration Gets or sets the maximum request size. The maximum request size in kilobytes. The default size is 4096 KB (4 MB). Configuration Property Attribute Integer Validator Attribute The selected value is less than RequestLengthDiskThreshold.


1 Answers

In your webconfig file, you need to declare the <location> tag with the path that way:

<location path="controller/action">
  <system.web>
    <!-- maxRequestLength is in kilobytes (KB)  -->
    <httpRuntime maxRequestLength="5120" /> <!-- 5MB -->
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- maxAllowedContentLength is in bytes (B)  -->
        <requestLimits maxAllowedContentLength="5242880"/> <!-- 5MB -->
      </requestFiltering>
    </security>
  </system.webServer>
</location>
like image 155
Alexandre Jobin Avatar answered Sep 21 '22 13:09

Alexandre Jobin