Search code examples
c#asp.nethttpmodule

redirect to error on exceeding fileupload size


I am trying to direct user to a error page when maximum fileupload size excedds.For this iam doing the following thing:

public void Init(HttpApplication application)
    {
        application.BeginRequest += new EventHandler(application_BeginRequest);
    }

    void application_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        if (context.Request.ContentLength > 4096000)
        {
            context.Response.Redirect("~/Error.aspx");
        }
    }
    public void Dispose()
    {
    }

But on uploading file with size more than the max filesize it is showing "connection reset" error. How should i do this.


Solution

  • Check this question: Display custom error page when file upload exceeds allowed size in ASP.NET MVC