Limiting Uploaded File Size

J

Johnson

I understand that setting maxRequestLength in Web.config will allow me to
limit the size of file users upload to an ASP.NET Web site.

Questions:
1. What happens when the user attempts to upload a file that is larger than
the max that I specify via maxRequestLength? Is there some exception I can
handle and then have some nice way to tell the user what happened?

2. Even better - is there any reasonably easy way to determine the file size
*before* the file is uploaded (i.e., check the size to determine if the file
should even be sent)?

Thanks!
 
L

Lau Lei Cheong

Johnson said:
I understand that setting maxRequestLength in Web.config will allow me to
limit the size of file users upload to an ASP.NET Web site.

Questions:
1. What happens when the user attempts to upload a file that is larger than
the max that I specify via maxRequestLength? Is there some exception I can
handle and then have some nice way to tell the user what happened?
Yes. There is exception that you can handle. But since browsers do not
accept response stream when this type of error occurs (That's why you see
the "server is not responding or DNS error" screen), there's little you can
do to tell the user what happens. The best you can do without extra
component will be to send an email to the user telling he/she about this.
The other option is, as Steve said, use one of the 3rd party solutions.
(Thick client is not a must in this case, I've found a way to work around
with a component using extra progress bar window, casing the upload page
being redirected to error page when the error happens, so not extra plugin
is required on the clients)
2. Even better - is there any reasonably easy way to determine the file size
*before* the file is uploaded (i.e., check the size to determine if the file
should even be sent)?
You must use thick clients then. Both javascript and vbscript do not expose
method to check that.
 
S

Steve C. Orr [MVP, MCSD]

I've found a way to work around with a component using

Can you please post this code? I'd love to see how it works.
 
L

Lau Lei Cheong

That's nothing trickly.

The basic idea is that, when the upload is cancelled/finished, the uploadid
will not be able to be found in the upload component. So in that case I just
check to see if the main window goes to the "upload finish" page if the
upload is not found. If it's true, the main window is redirected to the
error page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top