2011-12-22 92 views
5

我在子目錄(即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

回答

7

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

相關問題