Click here to Skip to main content
Rate this: bad
good
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:-
<system.webServer>
    <security>
          <requestFiltering>
        <requestLimits maxAllowedContentLength="41943040"/>
        </requestFiltering>
    </security>
</system.webServer>

And
<system.web>
    <httpRuntime maxRequestLength="40960" requestValidationMode="2.0" />
</system.web>

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();
        try
        {
            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
Comments
Sandeep Mewara at 24-Feb-13 3:37am
   
So, execution does come in Application_Error when length exceeds, right?
Muzaffar Ali Rana at 25-Feb-13 3:55am
   
Yes.
But after coming into the Application_Error code block, the page is not redirected.
Although I have used

Response.Clear();
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 at 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 at 26-Feb-13 8:46am
   
I removed the Try-Catch from this method, but it is still not working for me.
Muzaffar Ali Rana at 8-Mar-13 6:06am
   
Is there anybody to help me out this issue?
Thanks!

1 solution

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

Solution 1

You have to clear the error object before the redirect.

i.e.

HttpContext.Current.ClearError();
Response.Redirect("~/About.aspx", false);
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 280
1 Sebastiaan Meijerink 145
2 Sergey Alexandrovich Kryukov 108
3 Abhinav S 94
4 BillWoodruff 85
0 Sergey Alexandrovich Kryukov 6,558
1 OriginalGriff 6,288
2 Peter Leow 2,534
3 Abhinav S 2,358
4 Maciej Los 2,352


Advertise | Privacy | Mobile
Web02 | 2.8.150414.1 | Last Updated 20 Jun 2013
Copyright © CodeProject, 1999-2015
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