asp.net-mvc - ASP.NET MVC 在子文件夹 web.config 中忽略了 maxRequestLength 和 maxAllowedContentLength 吗?

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

我在子目录(即 Areas\Administration\Views)的 web.config 中设置了 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

最佳答案

在您的 Web 配置文件中,您需要使用以下路径声明 标记:

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

关于asp.net-mvc - ASP.NET MVC 在子文件夹 web.config 中忽略了 maxRequestLength 和 maxAllowedContentLength 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8605925/

相关文章:

c# - 重定向到页面但特定选项卡

asp.net - 每个 ASP.NET 应用程序实例是否都有持久存储?

jquery - IE10 - 选择要上传的文件后必须单击 2 次才能提交表单

javascript - 文件上传事件绑定(bind)

css - ASP.NET MVC View 中的 Ghost 自定义 Bootstrap HTML 元素

asp.net - 我应该使用哪个PreApplicationStartMethod?

c# - 如何清除浏览器后退按钮点击 MVC4 中的浏览器缓存?

asp.net-mvc - DisplayFormat 未应用于十进制值

ajax - 在 Razor View 上调用 ajax 后显示模型状态错误

java - 多部分帖子——上传文件