在web.config文件的 <configuration> </configuration>
中添加<httpRuntime executionTimeout="90" maxRequestLength="100000" useFullyQualifiedRedirectUrl="false" />
中添加<httpRuntime executionTimeout="90" maxRequestLength="100000" useFullyQualifiedRedirectUrl="false" />
<system.web>
<httpRuntime
maxRequestLength="4000"
useFullyQualifiedRedirectUrl="true"
executionTimeout="45"
versionHeader="1.1.4128"/>
</system.web>
</configuration>----------
核心:maxRequestLength="4000"改大就可以了
</httpRuntime>修改maxRequestLength的值即可
</httpRuntime>修改maxRequestLength的值即可
ByVal sender As Object, ByVal e As EventArgs) ' Fires at the beginning of each request
Dim i As Integer
'this number is in bytes, NOT kilobytes!!
Dim iMaxFileSize As Integer = 8000000
For i = 0 To Request.Files.Count - 1
If Request.Files.Item(i).ContentLength > iMaxFileSize Then
Response.Redirect( _
"FileToBig.aspx?filesize=" & _
Request.Files.Item(i).ContentLength)
Exit For
End If
Next
End SubThe "Application_BeginRequest" sub in the global.asax.vb file fires at the beginning of each request, BEFORE the data has been completely uploaded. This sub has access to the headers, and can look at the properties of any uploaded files. If a file is, in this example, larger than 8000 kilobytes (8000000 bytes), the user is redirected to your custom error page, along with a querystring containing the size of the file they tried to upload. You could include the filename too, or anything else you want to tell them. The important thing is that, upon redirecting the user, the server discards the input stream and you don't have a 300 meg file in memory on your server.There are a couple of interesting things to notice here. First, you are looking at individual files. If there are multiple file fields on the page, the user could still upload more than 8000k by uploading two 7000k files. If you want to deal with that situation, you may want to use "Request.ContentLength" instead of looping through the files, like this: Sub Application_BeginRequest( _
ByVal sender As Object, ByVal e As EventArgs) ' Fires at the beginning of each request
Dim i As Integer
'this number is in bytes, NOT kilobytes!!
Dim iMaxFileSize As Integer = 8000000
If Request.ContentLength > iMaxFileSize Then
Response.Redirect("RequestTooBig.aspx?size=" & _
Request.ContentLength )
End If
End SubThat code will take all of the uploaded files into consideration, and not allow any request that is larger than your limit.You may want to do a combination of both, and there are lots of variations on this, but I think you get the picture. Don't forget that if you are allowing anything larger than the default total request size of 4 megs you will still need to alter your web.config to allow it, otherwise you will still show your user an ugly error. Also remember that the web.config only deals with the overall size of the entire request, including text fields and anything else in your form.If you found this article useful (or not) we would really appreciate it if you would tell us about it using the link below.