Click here to Skip to main content
12,830,433 members (44,109 online)
Rate this:
Please Sign up or sign in to vote.
I am using Visual Studio 2010/ASP.NET/C-Sharp website.

I basically had an ASP.NET FileUpload control, for which I needed to cater the exception thrown for the following message:-
Maximum request length exceeded.

The maximum file size setting is set in the web.config as follows:-
        <requestLimits maxAllowedContentLength="41943040"/>

    <httpRuntime maxRequestLength="40960" requestValidationMode="2.0" />

Using Global.asax with validating file size in "Application_Error()", but it has not resolved my issue and it crashes at the Redirect when file size is greater and a redirect to Error Page is not working.

I have used the following code, although it is now running the Application_Error() Code section, but the problem is that it is not redirecting to the About.aspx page.

void Application_Error(object sender, EventArgs e) 
        // Code that runs when an unhandled error occurs
        Exception exc = Server.GetLastError();
            if (exc.Message.Contains("Maximum request length exceeded"))
                Response.Redirect("~/About.aspx", false);
            if (exc.InnerException.Message.Contains("Maximum request length exceeded"))
                Response.Redirect("~/About.aspx", false);
        catch (Exception ex)

I want to find out that how can I accomplish my requirements, since I am stuck for this since a couple of days.
Kindly help me in this regards as early as possible.
Posted 23-Feb-13 22:14pm
Sandeep Mewara 24-Feb-13 3:37am
So, execution does come in Application_Error when length exceeds, right?
Muzaffar Ali Rana 25-Feb-13 3:55am
But after coming into the Application_Error code block, the page is not redirected.
Although I have used

and then Response.Redirect("~/About.aspx");
But its not working.

And similarly I have used
Server.Clear(); with
Server.Transfer("About.aspx"); But still it is not working too.
Sandeep Mewara 26-Feb-13 0:21am
Could you please remove try-catch from this method. Just log the error or plain and simple redirect it.
Muzaffar Ali Rana 26-Feb-13 8:46am
I removed the Try-Catch from this method, but it is still not working for me.
Muzaffar Ali Rana 8-Mar-13 6:06am
Is there anybody to help me out this issue?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have to clear the error object before the redirect.


Response.Redirect("~/About.aspx", false);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170326.1 | Last Updated 20 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100