Handling the System.Web.HttpException: Maximum request length exceeded error

liunx

Guest
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: <!-- m --><a class="postlink" href="http://locahost/WebProject/UploadForm.aspx">http://locahost/WebProject/UploadForm.aspx</a><!-- m -->
The page cannot be displayed
The page you are looking for is currently unavailable. The web site?br />

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 youThe 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...

-ChrisHi,

Take a look at this article <!-- m --><a class="postlink" href="http://www.developer.com/db/article.php/10920_3426051_2">http://www.developer.com/db/article.php/10920_3426051_2</a><!-- m --> and tell me if you continue thinking the same.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?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.Hmmm... :confused:

I think that's out of my legue - sorry...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.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!

jtIf 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.
 
Back
Top