I have both maxRequestLength and maxAllowedContentLength set in web.config (20MB each) in a sub directory (i.e. Areas\Administration\Views). I have file uploading within administration and when I try to upload a large file (~9MB in this case) I get "Maximum request length exceeded". If I move the two settings to the root it works but I'd prefer not to do so. Any suggestions?
Technology: ASP.NET, .NET 4.0, MVC 3 and IIS 7 on Windows Server 2008 Enterprise.
Stack Trace:
[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
The MaxRequestLength property is used to set the maximum upload File Size Limit in older ASP.Net versions. But in ASP.Net Core, a new property, maxAllowedContentLength is used to increase the maximum upload File Size Limit. In this article I will explain with an example, how to set MaxRequestLength in ASP.Net Core.
Create a new MVC web project and name it "ImgFileSizeLimit". You need to add/update the values of "executionTimeout", "maxRequestLength" & "maxAllowedContentLength" properties if not already added in the "Web.config" file, as shown below. .....
But in ASP.Net Core, a new property, maxAllowedContentLength is used to increase the maximum upload File Size Limit. In order to increase the maximum upload File Size Limit in ASP.Net Core, the upload File Size Limit needs to be set in the following two locations.
Http Runtime Section. Max Request Length Property System. Web. Configuration Gets or sets the maximum request size. The maximum request size in kilobytes. The default size is 4096 KB (4 MB). Configuration Property Attribute Integer Validator Attribute The selected value is less than RequestLengthDiskThreshold.
In your webconfig file, you need to declare the <location> tag with the path that way:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With