Results 1 to 5 of 5

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

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70

    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

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

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

    Let me answer your question with a question. Have you tried putting code into your global.asax file?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70

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

    Hi plenderj,

    Yes, now I am trying it with the global.asax file, and it works fine on the server, but on the client machine appears the error (The page cannot be found...). The strange thing is that only happens with this specific error, for the rest of the errors or other code I put in the global.asax file, the client machine works accordingly (fine).

    In the 5 point of this page: http://bcp.bowstreet.com/library/exc...ile_upload.htm

    I read:

    "Note: If you use Microsoft Internet Explorer to upload a file that is more than the maximum file size specified the Web browser interprets that as a Web page that cannot be found. As a result, you will be shown the default error message for your application server when the browser cannot find a Web page.

    On the page that contains the File Upload control, you may want to include some text explaining the what the user can expect if they try to upload a file whose size is greater than the maximum file size property. There is no graceful way to handle the event (for example using an error handler method) in which a user tries to upload a file greater than the size allowed because the processing takes place within the browser, not in the Automation Engine."


    Do you understand it?
    I think that if I can handle that error on the server (simulating a client), Why isn' t it possible on a 'real' client machine?

    Thank you

  4. #4
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

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

    Well basically that page explains that if the client is running Internet Explorer and they try to upload something that's too big, it's going to give them the 'Page Cannot Be Found' error regardless. So you're best off Putting a warning on the page saying warning them that this is what they can expect.


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70

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

    I also understand this, anyway I find very strange that I can handle the error when I test the same page on server side with an IE browser as well, simulating a client, and the same page on a client machine it responds in a different way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width