简体   繁体   English

服务器端验证可将文件上传大小限制为5mb

[英]Server side validation to limit file upload size to 5mb

我要添加一个自定义验证器,以确保文件上传大小不应大于5MB。

Define the size using the maxRequestLength attribute of the <httpRuntime> tag (within the <system.web> tag ) of web.config file. 使用web.config文件的<httpRuntime>标记(在<system.web>标记内)的maxRequestLength属性定义大小。

ex: 例如:

<system.web>
    ...
    <httpRuntime 
      ...
      maxRequestLength="5242880"   //Number of Bytes (5MB)
      ...
    />
   ...
</system.web>


Showing an alert to the user when updating large file 在更新大文件时向用户显示警报

In the file uploading event handler, check for the 'ContentLength' of the 'PostedFile'. 在文件上传事件处理程序中,检查“ PostedFile”的“ ContentLength”。

if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLength > 5242880)
{
   // Relevant error message goes here...
}

It will be useful to refer to the FileUploadClass MSDN page as well. 同样,也可以参考FileUploadClass MSDN页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Blazor 服务器端上传文件 > 28.6MB 功能 - Blazor server side upload file > 28.6MB functionality C#中文件大小服务器端的限制 - Limit on a file size server side in C# ASP.NET MVC 3中的服务器端图像上载验证-限制文件类型,大小和尺寸 - Server side image upload validation in ASP.NET MVC 3 - Restricting File Type, Size and Dimensions 停止将大小超过5mb的文件附加到多个文件输入中 - stop attaching files that size more than 5mb to multiple file input 如何使用C#在WP8.1应用程序中将图像大小从5MB减少到2MB - How to reduce size of image from 5MB to 2MB in WP8.1 app using c# 如何限制 Blazor 服务器端请求大小 - How to limit Blazor Server Side request size Visual Studio没有响应上传大小为6MB的文件 - Visual studio is not responding to upload a file of size 6MB .net Core 2.0 文件上传大小限制 - .net Core 2.0 File Upload Size Limit Blazor 服务器 - websocket 连接失败 1006 - PDF 查看器(文件大小为 13mb 到 20mb) - Blazor Server - websocket connection to failed 1006 - PDF Viewer (with file size 13mb to 20mb) 如果超过大小限制,.net会在上传时按比例缩小服务器中的图像 - .net scale down images in server upon upload if past size limit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM