Как отобразить значимое сообщение об ошибке, если загружаемый файл слишком велик?C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Как отобразить значимое сообщение об ошибке, если загружаемый файл слишком велик?

Сообщение Anonymous »


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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»