Naveen
Naveen

Reputation: 51

Unable to Uploading Large File in .Net Core3.1 Web API Service

Unable to upload file greater than 250 MB from ASP.Net Application to BizTalk server via .Net Core services. We are deploying .Net core service in IIS with OutOfProcess mode.

We are able to upload large file (>250MB) from VisualStudio in debug mode. But not able to upload large file after deploying .net core services to IIS.

Tried with below Settings

Settings in ASP.Net application

Settings in .Net Core service web.config

Also set Kestrel Limits in Programs.cs

 .UseKestrel(option =>
         {
             option.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(30);
             option.Limits.MaxRequestBodySize = null;
         });

Tried with InProcess mode also, but did not work.

Upvotes: 1

Views: 1963

Answers (1)

Manoj Choudhari
Manoj Choudhari

Reputation: 5624

Why you are not able to upload 250 MB file when hosted in IIS?

This is because the content lengths you have configured is being used only if application is hosted inside Kestrel.

When you run application through visual studio, Kestrel is being used and that's why it works.

But when you host it in IIS, web.config setting drives the maximum content length.

How to fix this issue?

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.

You can add this manually by modifying the web.config file. the configuration is shown below. The important line is <requestLimits maxAllowedContentLength="52428800" />.

<?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>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
      <security>
        <requestFiltering>
           <!-- This will handle requests up to 1GB-->
           <requestLimits maxAllowedContentLength="1073741824" />
        </requestFiltering>
      </security>
    </system.webServer>
</configuration>

Refer this blog post for further details.

Upvotes: 1

Related Questions