上传文件时,我收到错误 - 超出范围异常
我添加了下面的代码试图摆脱它! - 用vb写的
dim filesize as string = FileUploadVal.PostedFile.ContentLength
If filesize > 1048576 then
des_label = "File is too large!"
End if
但仍然出现错误,有没有办法在上传之前设置文件限制?
答案 0 :(得分:1)
文件大小将大于web.config中的允许限制。您可以设置HttpRuntimeSection.MaxRequestLength以限制上传文件大小。
MaxRequestLength属性指定缓冲的限制 输入流的阈值。例如,可以使用此限制 防止由发布的用户引起的拒绝服务攻击 大文件到服务器MSDN
<httpRuntime
executionTimeout = "HH:MM:SS"
maxRequestLength = "number"
requestLengthDiskThreshold = "number"
useFullyQualifiedRedirectUrl = "[True|False]"
minFreeThreads = "number"
minLocalRequestFreeThreads = "number"
appRequestQueueLimit = "number"
enableKernelOutputCache = "[True|False]"
enableVersionHeader = "[True|False]"
apartmentThreading = "[True|False]"
requireRootedSaveAsPath = "[True|False]"
enable = "[True|False]"
sendCacheControlHeader = "[True|False]"
shutdownTimeout = "HH:MM:SS"
delayNotificationTimeout = "HH:MM:SS"
waitChangeNotification = "number"
maxWaitChangeNotification = "number"
enableHeaderChecking = "[True|False]"
/>