Click here to Skip to main content
14,636,152 members
Rate this:
Please Sign up or sign in to vote.
See more:
Context:

I want to upload multiple files but when max request size mentioned in the web.config file is exceeded, I get a timeout page in IE. To handle this i have overridden the Page.OnError method and it gets executed quite well but I don't get the desired result

Desired Result: redirect to DefaultErrorPage

I have already tried handling error in the Global.aspx, created default error page and configured it in the web.config file but nothing worked :(

Here is the code of OnError method:

protected override void OnError(EventArgs e)
        {
            HttpContext ctx = HttpContext.Current;

            Exception exc = ctx.Server.GetLastError();

            ctx.Server.ClearError();
            
            ctx.Server.Transfer("DefaultErrorPage.aspx");
            
            //base.OnError(e);
        }



Please help its urgent

Thnx in advance for your time and help

EDIT =======================

Thanks MalikRizwan for your time and effort

But after thorough search I found out the following thing(s):

When we upload multiple files or a single file or in any way if our request size exceeds masRequestSize defined in the web.config, we can't handle it at any level or in any try/catch block.

And why is that so ? Because IIS has to first suck up all the content and then after that the control passes to asp.net but remember the request size exceeded the maxRequestSize therefore, IIS cannot process the request, so it just ends the request (and as the request has ended therefore Request.Redirect()/Server.Transfer() won't work neither do the custom error page node defined in web.config) and the client sees white page of death (i mean timeout page)

The only solution I think is to use Flash/AJAX

I hope this will save lots of efforts by the people out there
Posted
Updated 5-Oct-10 3:09am
v2

1 solution

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

Solution 1

why don't you just increase max timeout time in web.config?
   
Comments
Phan7om 5-Oct-10 3:53am
   
Yeah I can do that but I want to handle the error gracefully
Moreover when we click on the upload button it immediately goes to timeout meaning I don't think it even tries to upload the files because the Max size is exceeded
MalikRizwan 5-Oct-10 5:02am
   
are you testing in development environement when timeout immediately occurs? its normal if that is the case.. since you are upload file on your own local system.

So you mean when there is timeout error, they should see ERRORPAGE?
Phan7om 5-Oct-10 5:27am
   
Yeah I am testing it on my dev machine

and yes I want to display an error page on timeout (BTW is it even possible to display error page on timeout ?)
Phan7om 5-Oct-10 5:28am
   
one thing I missed to tell you is that when I debugged the application the above method (OnError) did get executed and I was astonished to see that the transfer() didn't transfer to the DefaultErrorPage.aspx
MalikRizwan 5-Oct-10 8:36am
   
Why don't you just put your code in try catch and catch "TimeoutException"?
MalikRizwan 5-Oct-10 8:41am
   
Ignore my last message please..

When you use FileUpload.. before uploading you can count number of bytes in file you are uploading.. using "ContentLength" property. use this property and match length of uploaded file with one you defined in web.config.. if uploaded file size is greater than that.. redirect to error page.
as when your application times out. you can not catch it until unless you write sometime to handle that on IIS level.

Please rate my answer if it helps

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




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