|
-
Dec 23rd, 2004, 11:47 AM
#1
Thread Starter
Lively Member
Handling the System.Web.HttpException: Maximum request length exceeded error
I limited the upload file size in my web.config to 320KB, thus:
Code:
<configuration>
<system.web>
<httpRuntime maxRequestLength="320" />
</system.web>
</configuration>
After that, when I try to upload a file bigger than 320KB from the FormUpload.aspx page, from the localhost machine, I see an error page for less than 1 second, and after that I am redirected to the original FormUpload.aspx page. If I try the same thing from a client machine, I receive the ugly error page:
Address bar: http://locahost/WebProject/UploadForm.aspx
The page cannot be displayed
The page you are looking for is currently unavailable. The web site…
To solve that problem I wrote the FormUpload.aspx page thus:
Code:
<%@ Page Language="VB" Debug="True" %>
<script language="VB" runat="server">
Sub Page_Load(Sender as object, e as EventArgs)
If Session("ImageTooLarge") = True Then
lblTooLarge.Text() = "The file is bigger than 320KB!!"
Session("ImageTooLarge") = False
Else
If IsPostBack Then
lblTooLarge.Text() = "The file is Ok! Smaller or equal than 320KB"
End If
End If
End Sub
Sub Page_Error(Sender as object, e as EventArgs)
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException, HttpException)
' Verify the expected error
If checkException.GetHttpCode = 400 And checkException.ErrorCode = -2147467259 Then
Session("ImageTooLarge") = True
Server.ClearError()
Response.Redirect("FormUpload.aspx")
End If
End If
End Sub
</script>
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form_1" enctype="multipart/form-data" method="post" runat="server">
<input type="file" id="attached_file" runat="server" /><br><br>
<asp:button ID="buton_1" runat="server" Text="Test the file" /><br><br><br>
<asp:label ID="lblTooLarge" ForeColor="#FF0000" runat="server"></asp:label>
</form>
</body>
</html>
And if the file uploaded from this page is bigger than 320KB a beautiful message text label appears saying “The file is bigger than 320KB!!”, and I said cool!. But this only happens from the localhost machine, when I test the same page in a client machine the same ugly error page appears (The page cannot be displayed…).
Somebody knows why this happens?
Thank you,
Cesar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|