By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,636 Members | 1,814 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,636 IT Pros & Developers. It's quick & easy.

maxRequestLength and FileUpload

P: n/a
Jay
I have been trying to use maxRequestLength to stop users from uploading
large files. It put this code in the web.config file:
The upload works fine.
When I select a large file I get the "Page cannot be displayed" message,
which is correct.

The problem is that I am trying redirect the user to a meaningful error
page or back to the upload page showing an error message. To do this I put
the code below in Page_Error or Application_Error. I have epxerimented with
both.

Server.ClearError()
Session("UPLOADERROR") = "yes"

Response.Redirect("ErrorPage.aspx")

No matter what I do I get the "Page cannot be displayed" messaage, rather
than being redirected. When this error message is displayed the URL in the
browser is showing update.aspx, not the error page.apsx. If I refresh I
get the Upload.aspx page. When I try to upload a large file and I set a
break point on Page_Error I can step to Reponse.redirect("ErrorPage.aspx")
but it does not redirect to ErrorPage.aspx.

I have also experimented with the web.config setting customErrors but I get
the same thing.

Help!!

Jay
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Seva Voloshin sent me this code, which displays a friendly error message when somebody upload a file that is too large:

private void Page_Load(object sender, System.EventArgs e)

{

if(!IsPostBack)

{

//use session to retrieve value

object imageStatus = Session["ImageTooLarge"];

if(imageStatus != null && (bool)imageStatus == true)

{

Label1.Visible = true;

Session["ImageTooLarge"] = null;

}

}

}







protected void Application_Error(Object sender, EventArgs e)

{

if(System.IO.Path.GetFileName(Request.Path) == "WebForm1.aspx")

{

HttpException checkException = Server.GetLastError() as HttpException;



//Verify the expected error

if(checkException.GetHttpCode() == 400 && checkException.ErrorCode == -2147467259)

{

//Error 400 = bad request, user tried to upload a file that's too large

Session["ImageTooLarge"] = true;

Server.ClearError();

Response.Redirect("WebForm1.aspx");

}

}

}
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Jay" <Ar***********@microsoft.com> wrote in message news:ud*************@tk2msftngp13.phx.gbl...
I have been trying to use maxRequestLength to stop users from uploading
large files. It put this code in the web.config file:


The upload works fine.
When I select a large file I get the "Page cannot be displayed" message,
which is correct.

The problem is that I am trying redirect the user to a meaningful error
page or back to the upload page showing an error message. To do this I put
the code below in Page_Error or Application_Error. I have epxerimented with
both.

Server.ClearError()
Session("UPLOADERROR") = "yes"

Response.Redirect("ErrorPage.aspx")

No matter what I do I get the "Page cannot be displayed" messaage, rather
than being redirected. When this error message is displayed the URL in the
browser is showing update.aspx, not the error page.apsx. If I refresh I
get the Upload.aspx page. When I try to upload a large file and I set a
break point on Page_Error I can step to Reponse.redirect("ErrorPage.aspx")
but it does not redirect to ErrorPage.aspx.

I have also experimented with the web.config setting customErrors but I get
the same thing.

Help!!

Jay

Nov 19 '05 #2

P: n/a
dgm
I'm trying this in VS Beta2 and ASP.NET 2.0, and no matter what I try I
cannot forward to an Error Page or back to the original page. I keep getting
the "The Page Cannot be Displayed" message.

Thru many hours of testing I have discovered several facts:
1) The transfer from Global.ascx actually Redirects to original page, but
after the load event the "... Cannot Display..." message occurs.
2) After the error, and redirection to original page; the ContentLength
property has the same value as before the error. It's as if the page is
still trying to upload the file. Is there anyway to cancel the page handler,
or Upload process?
3) I can capture the error on the Page's Error event, but the same problems
occur.
4) After "...Cannot Display..." message it is very difficult to get back to
download page. Refresh and the Back Button don't work 95% of the time.
Usually I have to close Browser and open new Browser.

Thanks
"Steve C. Orr [MVP, MCSD]" wrote:
Seva Voloshin sent me this code, which displays a friendly error message when somebody upload a file that is too large:

private void Page_Load(object sender, System.EventArgs e)

{

if(!IsPostBack)

{

//use session to retrieve value

object imageStatus = Session["ImageTooLarge"];

if(imageStatus != null && (bool)imageStatus == true)

{

Label1.Visible = true;

Session["ImageTooLarge"] = null;

}

}

}



protected void Application_Error(Object sender, EventArgs e)

{

if(System.IO.Path.GetFileName(Request.Path) == "WebForm1.aspx")

{

HttpException checkException = Server.GetLastError() as HttpException;

//Verify the expected error

if(checkException.GetHttpCode() == 400 && checkException.ErrorCode == -2147467259)

{

//Error 400 = bad request, user tried to upload a file that's too large

Session["ImageTooLarge"] = true;

Server.ClearError();

Response.Redirect("WebForm1.aspx");

}

}

}
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Jay" <Ar***********@microsoft.com> wrote in message news:ud*************@tk2msftngp13.phx.gbl...
I have been trying to use maxRequestLength to stop users from uploading
large files. It put this code in the web.config file:
The upload works fine.
When I select a large file I get the "Page cannot be displayed" message,
which is correct.

The problem is that I am trying redirect the user to a meaningful error
page or back to the upload page showing an error message. To do this I put
the code below in Page_Error or Application_Error. I have epxerimented with
both.

Server.ClearError()
Session("UPLOADERROR") = "yes"

Response.Redirect("ErrorPage.aspx")

No matter what I do I get the "Page cannot be displayed" messaage, rather
than being redirected. When this error message is displayed the URL in the
browser is showing update.aspx, not the error page.apsx. If I refresh I
get the Upload.aspx page. When I try to upload a large file and I set a
break point on Page_Error I can step to Reponse.redirect("ErrorPage.aspx")
but it does not redirect to ErrorPage.aspx.

I have also experimented with the web.config setting customErrors but I get
the same thing.

Help!!

Jay

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.