Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm working on a .NET Core 3.1 webapp using C#. I use Blazor ServerSide as my front-end. The app is hosted by Azure. On my page I have an upload component. When I upload 1 file it works fine. When I upload 2-3 files it is still working but when I upload more files I get this error:

(Serilog.AspNetCore.RequestLoggingMiddleware) HTTP "POST" "/api/foo/2/bar" responded 500 in 18501.3265 ms
Microsoft.AspNetCore.Connections.ConnectionResetException: The client has disconnected
 ---> System.Runtime.InteropServices.COMException (0x800704CD): An operation was attempted on a nonexistent network connection. (0x800704CD)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Server.IIS.Core.IO.AsyncIOOperation.GetResult(Int16 token)

Most likely it has something to do with the file size of the POST. When running my webapp in Visual Studio I don't have any problems.

I also see this warning in my logging:

(Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer) Increasing the MaxRequestBodySize conflicts with the max value for IIS limit maxAllowedContentLength. HTTP requests that have a content length greater than maxAllowedContentLength will still be rejected by IIS. You can disable the limit by either removing or setting the maxAllowedContentLength value to a higher limit.

I've tried numerous options to increase the limit:

In my controller:

[Authorize]
[DisableRequestSizeLimit]
public class UploadController : BaseApiController

In Startup.cs:

            // To bypass the file limit:
            services.Configure<FormOptions>(options =>
                options.ValueLengthLimit = int.MaxValue;
                options.MultipartBodyLengthLimit = long.MaxValue; // <-- !!! long.MaxValue
                options.MultipartBoundaryLengthLimit = int.MaxValue;
                options.MultipartHeadersCountLimit = int.MaxValue;
                options.MultipartHeadersLengthLimit = int.MaxValue;
            services.Configure<IISServerOptions>(options =>
                options.MaxRequestBodySize = null;

But still no luck.

Am I missing yet another setting or is this error not related to the upload size?

Thanks @DorisLv for the link. But they are talking about catching the error and reporting a better message. I need to prevent the error and be able to upload multiple files. If my problem is not related to the filesize limits might it be due to time-outs? Can I increase that value? – Paul Meems Sep 25, 2020 at 6:33 I don't think it would work, because there is an outage in Azure, which may cause for this issue. It's not your code's fault or file's. You can have a try, but my suggestion is redeploy a new web app and try again. Please let me know if it work or not. – Doris Lv Sep 25, 2020 at 7:30 What do you mean 'there is an outage in Azure'. When I look at status.azure.com I don't see any problems. And how would redeploying solve my problem? Should I redeploy to a different subscription? Because I'm still developing and testing I'm using the Free WebApp instance. Might that be related? – Paul Meems Sep 25, 2020 at 8:19 Sorry I forgot to say "maybe" there was an outage, my fault~ Maybe it realated, because web app share instance in free tier, some problem may cause randomly in yours just because of others fault... Sometimes I got this error, and redeploy in the same resource group works in my way. Just a suggestion, and you can try. – Doris Lv Sep 25, 2020 at 8:47

It took me weeks to solve this together with help from Microsoft Support.
It appears the problem was only with a few clients.
I had changed the WebApp setting in Azure to use HTTP v2 instead of HTTP v1.
And it looks like in the connection from my browser to Azure one hop was dropping the HTTP v2 packages. When I reset the setting the problem went away.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.