Click to See Complete Forum and Search --> : Handling the System.Web.HttpException: Maximum request length exceeded error


erick30
12-23-2004, 11:29 AM
I limited the upload file size in my web.config to 320KB, thus:

<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:

<%@ 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

ccamarat
01-20-2005, 07:19 AM
The fact that you're getting "The Page Cannot Be Displayed" tells me that you might have a config problem on either your server or your client (ok, that deserves a "duh!" :rolleyes: ) Here's what I'm trying to get at.

1. Possible server problems: Normally I see this on IIS not serving .aspx files; .NET has it's own unique look to it (red, white, and yellow).
It might have something to do with the release configuration; is your app being compiled as 'Debug'?
Web.Config - is Custom Errors set correctly?
2. Possible Client problem: Is the client's browser configured to "Show Friendly Error Messages"? IE has the option, under Internet Options / Advanced to override the site's error message with its own "Page Cannot be displayed" error (which is somehow more 'friendly'? :confused: )
That's all I can think of without actually seeing the problem...

-Chris

erick30
01-21-2005, 11:31 AM
Hi,

Take a look at this article http://www.developer.com/db/article.php/10920_3426051_2 and tell me if you continue thinking the same.

ccamarat
01-22-2005, 05:06 AM
Nope. :D

Given the information there it strikes me as odd that the app would behave differently on two different machines. Did their solution work?

erick30
01-24-2005, 06:45 AM
That solution it does the same, in the server works fine but not in client machines, where the error page 'The page cannot be found' also appears.

ccamarat
01-26-2005, 02:23 AM
Hmmm... :confused:

I think that's out of my legue - sorry...

zogmrbill
01-31-2006, 04:00 PM
When the maxRequestLength attribute is set in the Machine.config file and then a request is posted (for example, a file upload) that exceeds the value of maxRequestLength, a custom error page cannot be displayed. Instead, Microsoft Internet Explorer will display a "Cannot find server or DNS" error message.

jjt
10-30-2006, 11:34 PM
Hi,

Did you end up finding the solution to this? I am having the exact same problem (although using c#). redirection works great on local but stops working from clients...have wasted many hours looking for a solution!

jt

brett_l
10-17-2007, 06:21 PM
If your remote machine is running IIS 6.0, then you may need to edit the metadata.xml file in IIS, because the default upload size in IIS 6.0 is 200kb.

Sorry I don't have the actual KB#, but this is verbatim from MS:

Error:

Request object error 'ASP 0104 : 80004005' Operation not Allowed Reason:

IIS6.0 prevents the upload of files more than +200Kb. So you need to make some changes in the default IIS settings first. Background:

For IIS6.0 users, the AspMaxRequestEntityAllowed property specifies the maximum number of bytes allowed in the entity body of an ASP request. If a Content-Length header is present and specifies an amount of data greater than the value of AspMaxRequestEntityAllowed, IIS returns a 403 error response. This property is related in function to MaxRequestEntityAllowed, but is specific to ASP request. Whereas you might set the MaxRequestEntityAllowed property to 1 MB at the general World Wide Web Publishing Service (WWW Service) level, you may choose to set AspMaxRequestEntityAllowed to a lower value, if you know that your specific ASP applications handle a smaller amount of data. Solution:

Open your metabase.XML which is located in c:\Windows\System32\Inetsrv find the line "AspMaxRequestEntityAllowed" and change it to "1073741824". This is 1GB - of course you can enter another value to suit your needs. NOTE: Before you edit the file, be sure to stop the IIS service first or else you won't be able to save the file.

justin_yj
10-29-2010, 05:32 PM
In Application_Error() function of Global.ascx.cs file, put the following line:

Response.Close();

Read the following link to find more information.

Handle the “Maximum request length exceeded.” error for AsyncFileUpload control. (http://justinyue.wordpress.com/2010/10/29/handle-the-maximum-request-length-exceeded-error-for-asyncfileupload-control/)

:rolleyes: