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

问题描述:

我在子目录(即Areas \ Administration \ Views)中设置了web.config中的maxRequestLength和maxAllowedContentLength(每个20MB)。我在管理文件中上传文件,当我尝试上传大文件(在这种情况下为〜9MB)时,我得到“超出最大请求长度”。如果我将这两个设置移动到根目录,但我宁愿不这样做。有什么建议么?ASP.NET MVC在子文件夹web.config中忽略maxRequestLength和maxAllowedContentLength?

技术: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

如果我的回答将帮助你,请接受它作为答案。否则,请发表评论以告诉我们有关您的问题的更多信息。 – 2012-08-25 02:46:36

在你的webconfig文件,你需要使用路径声明<位置>标签那样:

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

你的意思是,如果我有一个名为'VideoController'的控制器和一个名为'Save'的动作,那么我必须将**路径**设置为'path =“Video/Save”'?我正在谈论ASP.NET Web API。 – 2015-03-29 06:54:06

+0

不确定关于WebAPI路径。该解决方案适用于MVC。也许你可以尝试像“API /控制器/行动”? – 2015-03-30 14:27:44