I'm trying to limit the size of files that can be uploaded to my page. I found I can accomplish this using RequestFormLimitsAttribute.
[RequestFormLimits(MultipartBodyLengthLimit = MaxUploadFileLength)] public class BulkTruckUploadModel : PageModel { // ... } This definitely prevents larger files from being uploaded. But it causes Microsoft Edge to just throw up a generic error page.

Is there any way to capture this error and display a more meaningful error message?
Here is my form that submits the file.
Cancel And here's my handler that gets the file.
public async Task OnPostAsync() { if (ModelState.IsValid) { try { // Read the file from BulkUpload.File.OpenReadStream() } catch (Exception ex) { // Handle exceptions } } return Page(); } Update: The goal here is to prevent denial-of-service attacks by someone trying to upload enormous files. I could also just remove the size limitation and then check the file length property from code. But it isn't clear to me if this approach prevents very large files from impacting the server. (Does this prevent uploading big files, or just check the length after they've been uploaded?)
Источник: https://stackoverflow.com/questions/780 ... is-too-big