Asp.Net Core Kestrel設定Request Body Size

前兩天同事利用Web Api Post上傳檔案碰到了Request body too large的問題,我想到過去的經驗就是因為預設值比較小,所以改一下設定應該就可以Work了。

Request body too large

Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Request body too large.
at Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(RequestRejectionReason reason)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1ContentLengthMessageBody.OnReadStarting()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.TryStart()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.ConsumeAsync()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication1 application)

通常不會把每一個設定值都記在腦中,所以就搜尋了一下Kestrel Server的設定應該在appsettings.json檔案中如何調整,查到了設定MaxRequestBodySize的C#程式碼,但是翻了很多篇網路上的文章都沒有找到如何在設定檔裡面調整的方法…

閱讀全文