0

When i try to upload large files(>30Mb) to my server I get generic 404 error. But it does not allow me to render appropriate message("File too large") to make sure that user understands why upload fails. So is there a way to catch this error before IIS returns a 404 response back to the user and return a different header with a custom error?

Because right not the only way for me to know that this error was due to a file size is thru analyzing server logs for the failed requests.

If not, is there a way to access the maxAllowedContentLength directive thru the controller to pass this value back to the ui so user can compare the content length before upload?

AnKing
  • 1,994
  • 6
  • 31
  • 54
  • Does [Asp.Net Check file size before upload](https://stackoverflow.com/q/3094748/1115360) give you any ideas? – Andrew Morton Jan 31 '20 at 19:55
  • Client validation only for regular user purpose on the frontend. But server limitation on iis + firewall is main purpose of security and vulneralibility, so you can manipulate server error response on the client site. – OO7 Jan 31 '20 at 21:05
  • Here is the official docs for asp.net core uploading files. Security, streaming, file size and etc. If you just want to increase the upload limit I would recommend to use the attribute [RequestSizeLimit(52428800)]. https://learn.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1#kestrel-maximum-request-body-size – Zsolt Bendes Jan 31 '20 at 21:50

0 Answers0