5
votes

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
1
If my answer is helping you, please accept it as the answer. Otherwise, post a comment to tell us more info about your problem.Alexandre Jobin

1 Answers

7
votes

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>