Deal with large file size when uploading
Hosted on IIS
Remember in the ASP.NET, we used to set maxRequestLength
in web.config file to increase the default limit of 4MB. Like,
1
2
3
4
5
<
configuration
>
<
system.web
>
<
httpRuntime
maxRequestLength
=
"xxx"
/>
</
system.web
>
</
configuration
>
Similarly, for ASP.NET Core application, we can increase the default limit of 30MB by setting maxAllowedContentLength
property in the web.config
file. The default ASP.NET Core application template doesn’t create the web.config
file. It is created when you publish the application. However, you can also add it manually (if not present) to the root of the application with the following code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
<!-- To customize the asp.net core module uncomment and edit the following section.
For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
<
system.webServer
>
<
handlers
>
<
remove
name
=
"aspNetCore"
/>
<
add
name
=
"aspNetCore"
path
=
"*"
verb
=
"*"
modules
=
"AspNetCoreModule"
resourceType
=
"Unspecified"
/>
</
handlers
>
<
security
>
<
requestFiltering
>
<!-- This will handle requests up to 50MB -->
<
requestLimits
maxAllowedContentLength
=
"52428800"
/>
</
requestFiltering
>
</
security
>
</
system.webServer
>
</
configuration
>
You are required to define maxAllowedContentLength
in the security section. You can read more about the web.config
file for ASP.NET Core here.
In order to create the reverse proxy between IIS and the Kestrel server, the web.config file must be present at the content root path (typically the app basepath) of the deployed app. This is the same location as the website physical path provided to IIS. This setting only applies to IIS.
maxRequestLength
in web.config file to increase the default limit of 4MB. Like,
1
2
3
4
5
| < configuration > < system.web > < httpRuntime maxRequestLength = "xxx" /> </ system.web > </ configuration > |
maxAllowedContentLength
property in the web.config
file. The default ASP.NET Core application template doesn’t create the web.config
file. It is created when you publish the application. However, you can also add it manually (if not present) to the root of the application with the following code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| <? xml version = "1.0" encoding = "utf-8" ?> < configuration > <!-- To customize the asp.net core module uncomment and edit the following section. For more info see https://go.microsoft.com/fwlink/?linkid=838655 --> < system.webServer > < handlers > < remove name = "aspNetCore" /> < add name = "aspNetCore" path = "*" verb = "*" modules = "AspNetCoreModule" resourceType = "Unspecified" /> </ handlers > < security > < requestFiltering > <!-- This will handle requests up to 50MB --> < requestLimits maxAllowedContentLength = "52428800" /> </ requestFiltering > </ security > </ system.webServer > </ configuration > |
maxAllowedContentLength
in the security section. You can read more about the web.config
file for ASP.NET Core here.
Comments
Post a Comment