Header add

 In this article we will discuss Set MaxRequestLength in ASP.Net Core.

Here we will explain how to Uploading Large Files in ASP.Net Core. The maximum upload File Size Limit in ASP.Net Core is 28 MB, which means user will not be allowed to upload Files of size greater than 28 MB.

Thus this article will provide details about how you can increase the limit and upload files greater than 28 MB in ASP.Net Core.

</> Find the Source Code in Github

Before start this article, please visit our previous article Upload Large files in ASP .NET using Generic Handler.



Increasing File Size Limit in ASP.Net Core

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.
  • Decorating the Action method that handles upload with RequestFormLimits attribute and setting the maximum allowed File Size Limit.
  • Setting the maximum allowed File Size Limit in the maxAllowedContentLength setting in the Web.Config file.
Controller

The Action method Index by default supports the GET operation and hence another overridden method for POST operation is created which accepts the parameter which is a collection of type IFormFile.

First a check is performed whether Directory (Folder) exists if not then the Directory (Folder) is created inside the www Folder using IHostingEnvironment interface and then a loop is executed and one by one each file is saved to the Directory (Folder).



View
The View consists of an HTML Form which has been created using the Razor Tag attributes with the following attributes.
asp-action – Name of the Action. In this case the name is Index.
asp-controller – Name of the Controller. In this case the name is Home.
method – It specifies the Form Method i.e. GET or POST. In this case it will be set to POST.
There is an HTML FileUpload element, a Submit Button and a SPAN element for displaying Message enclosed in a Form element.
The HTML FileUpload element has been specified with an additional HTML5 attribute multiple = “multiple” in order to allow user to select multiple files.

Adding Web.Config File and setting the maximum upload File Size Limit
Add a Web Configuration File
upload-large-files-in-aspnet-core-webconfig

In the Web.Config file, set the maxAllowedContentLength setting to 100 MB as shown below.







Output

Post a Comment

Previous Post Next Post