[英]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.