【问题标题】:ASP.NET MVC are maxRequestLength and maxAllowedContentLength ignored in a subfolder web.config?ASP.NET MVC 在子文件夹 web.config 中是否忽略了 maxRequestLength 和 maxAllowedContentLength?
【发布时间】:2011-12-22 15:20:36
【问题描述】:

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

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

【问题讨论】:

  • 如果我的回答对你有帮助,请采纳。否则,请发表评论,告诉我们有关您的问题的更多信息。

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


【解决方案1】:

在您的 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>

【讨论】:

  • 您的意思是,如果我有一个名为VideoController 的控制器和一个名为Save 的操作,那么我必须将路径 设置为path="Video/Save"?我说的是 ASP.NET Web API。
  • 不确定 WebAPI 路径。此解决方案适用于 MVC。也许你可以尝试类似“api/controller/action”的东西?
猜你喜欢
  • 1970-01-01
  • 2013-02-09
  • 2020-03-21
  • 2012-10-06
  • 2018-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-07
相关资源
最近更新 更多