473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

maxRequestLength and FileUpload

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
2 5005
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Peter Row | last post by:
Hi, To allow users to upload files larger than 4MB in size I added: <httpRuntime maxRequestLength="102400" executionTimeout="600" /> ...to my web.config file. Fair enough this works fine....
25
by: moondaddy | last post by:
I have an application where users need to upload images and in my web.config file I have a setting like this: <httpRuntime maxRequestLength="512" /> Which restricts image larger than 500k from...
1
by: toto | last post by:
Example: <configuration> <system.web> <httpRuntime maxRequestLength="2048" /> </system.web> </configuration> I need to kno in my code the value of key maxRequestLength. Thanks in advance.
2
by: Jay | last post by:
I have been trying to use maxRequestLength to stop users from uploading large files. It put this code in the web.config file: <httpRuntime maxRequestLength="128" /> --The upload works...
3
by: Stephen Ahn | last post by:
Given a web service method defined like this : public string EchoByteArray(byte data) { return data.Length.ToString() + " bytes received"; } If, from a Windows C# app, I call this web...
2
by: Joseph Geretz | last post by:
I'm developing a Web Service using DIME to download and upload files from and to an IIS server. In order to increase the download filesize to unlimited, I have the following block in my App.config...
2
by: Islamegy® | last post by:
I'm use FormView for editing a photo gallery... I add FileUpload control to upload images to the Gallery. I'm binding my Formview to objectdatasource i tried upload images onItemInserting &...
1
by: Marko Vuksanovic | last post by:
I am trying to implement an upload progress indicator using atlas, using the following workaround: http://forums.asp.net/thread/1321664.aspx This is the code in FileUpload.apsx file is as...
0
by: salty | last post by:
I'm running into the notorious 4MB upload limit. I see where one answer is to set a higher limit to the httpRunTime MaxRequestLength setting in web.config. However this affects the whole...
0
by: Christian Schlemmer | last post by:
If my code will run into the filesize-limit condition, the INSERT-statement will be executed. is there a way to avoid that? Protected Sub DetailsView1_RowInserting(ByVal sender As Object,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.