ASP.NET MVC是在子文件夹web.config中忽略的maxRequestLength和maxAllowedContentLength吗?

时间:2011-12-22 15:20:36

标签: asp.net-mvc asp.net-mvc-3 file-upload iis-7 web-config

我在子目录(即Regions \ Administration \ Views)中的web.config(每个20MB)中设置了maxRequestLength和maxAllowedContentLength。我在管理中上传文件,当我尝试上传大文件(在这种情况下约为9MB)时,我得到“超出最大请求长度”。如果我将两个设置移动到root它可以工作,但我不想这样做。有什么建议吗?

技术:Windows Server 2008 Enterprise上的ASP.NET,.NET 4.0,MVC 3和IIS 7.

堆栈追踪:

[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 个答案:

答案 0 :(得分:7)

在您的网络配置文件中,您需要声明&lt; location&gt;标记路径:

<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>