Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Henk Poell 2 posts 22 karma points
    Jan 26, 2010 @ 13:49
    Henk Poell
    0

    How to implement: custom error page after exceeding httpRuntime maxRequestLength

    I'm using 4.0.2.1 with IIS 5.1 on XP.

    In our appication, users can upload larger files. Of course you can set the limit in the web.config:

        <httpRuntime maxRequestLength="5250" executionTimeout="360"/>

    Works as advertised, but when the upload gets over 5MB, there is this immediate IIS error that -it seems- you cannot make any prettier for the user. Or can you? I have been looking at IIS forums, and what's suggested is creating a global.asax file and redirecting in the Application_Error. It didn't work. Am I doing something toally wrong? Or is it that you have to adapt recompile umbraco for this?
    I wonder if I shouldn't start thinking about setting the limit to 1GB (thus opening the door a bit for DOS attacks) and let the usercontrol throw exceptions instead. Has anyone solved this? We expect people using the site who don't know what a megabyte is.
    Henk Poell / Mirabeau

  • John Ligtenberg 53 posts 214 karma points
    Nov 26, 2012 @ 17:13
    John Ligtenberg
    0

    Hello Henk,

    The only solution which eventually worked for me was making an HttpModule, in the App_Code directory. I'm using 4.7

    In web.config, underI added the following line:

     <add name="MaxRequestLengthErrorHandlerModule" type="MaxRequestLengthErrorHandlerModule"/>

     
    Below is the code for the HttpModule. The error message sent back is rather specific for my particular situation, responding to an Ajax call.

    John Ligtenberg / Royal Tropical Institute / Amsterdam

     

    using System;
    using System.Web;
    public class MaxRequestLengthErrorHandlerModule : IHttpModule
    {
    public MaxRequestLengthErrorHandlerModule()
    {
    }

    public String ModuleName
    {
    get { return "MaxRequestLengthErrorHandlerModule"; }
    }

    // In the Init function, register for HttpApplication
    // events by adding your handlers.
    public void Init(HttpApplication application)
    {
    application.BeginRequest +=
    (new EventHandler(this.Application_BeginRequest));
    application.EndRequest +=
    (new EventHandler(this.Application_EndRequest));
    }

    private void Application_BeginRequest(Object source,
    EventArgs e)
    {
    // Create HttpApplication and HttpContext objects to access
    // request and response properties.
    HttpApplication application = (HttpApplication) source;
    HttpContext context = application.Context;
    string filePath = context.Request.FilePath;

    try
    {
    if (context.Request.Files.Count > 0 && context.Request.Files[0].ContentLength > 3200000)
    {
    context.Response.Write(@"<html><head><script> parent.__uploadhandler_0_error(""Bestand is groot"") </script></head></html>");
    context.Response.End();
    }
    }
    catch (HttpException ex)
    {
    context.Response.Write(@"<html><head><script> parent.__uploadhandler_0_error(""Bestand is groot"") </script></head></html>");
    context.Response.End();
    }

    }


    private void Application_EndRequest(Object source, EventArgs e)
    {
    HttpApplication application = (HttpApplication)source;
    HttpContext context = application.Context;

    }

    public void Dispose() { }
    }
Please Sign in or register to post replies

Write your reply to:

Draft