473,387 Members | 1,504 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,387 software developers and data experts.

Programmable limits on upload size

In my ASP.NET application, I'd like to set limits on the maximum size of an
uploaded file. Normally I'd just

set the maxRequestLength of the httpRuntime element in web.config. But in
this case, I have a few different

aspx pages and I want the limit set differently for each. Yes, I could put
each in its own folder, each with

its own web.config, but that is rather awkward for this application.

Alternatively, I could leave the limit set in web.config to the largest
limit, and then in the other pages,

do my own checking, throwing an error if the ContentLength was too large.

But if the goal here is preventing a DOS attack on my server by someone who
is uploading lots of giant files,

maybe this is too late. That is, by the time my code gets to run, maybe the
content is already all uploaded

and has consumed the server resources. I'd rather be able to stop things
earlier in the process.

Looking at some Reflector code, it appears that the method
Request.GetEntireRawContent is actually doing the

reading of the input stream, and this is called very early in page handling,
by the first reference to the

Form contents. But I'm not sure I'm reading this correctly. If I look at
Request.InputStream at PageLoad

time, it says that it is still at position 0. Does that mean that the
content really hasn't been streamed in

yet?

Also I wonder what I can trust. The simple thing is just to check
Request.ContentLength, but I assume that a

bad guy can just fake that to be a small number. Is the InputStream length a
real number that can be trusted?

Any suggestions would be appreciated.

--
....Mike
Jun 27 '08 #1
2 2456
i can't help u with streams, but please use capctha to avoid robot
uploading

On 29 Apr, 09:27, Mike Kraley <mkra...@community.nospamwrote:
In my ASP.NET application, I'd like to set limits on the maximum size of an
uploaded file. Normally I'd just

set the maxRequestLength of the httpRuntime element in web.config. But in
this case, I have a few different

aspx pages and I want the limit set differently for each. Yes, I could put
each in its own folder, each with

its own web.config, but that is rather awkward for this application.

Alternatively, I could leave the limit set in web.config to the largest
limit, and then in the other pages,

do my own checking, throwing an error if the ContentLength was too large.

But if the goal here is preventing a DOS attack on my server by someone who
is uploading lots of giant files,

maybe this is too late. That is, by the time my code gets to run, maybe the
content is already all uploaded

and has consumed the server resources. I'd rather be able to stop things
earlier in the process.

Looking at some Reflector code, it appears that the method
Request.GetEntireRawContent is actually doing the

reading of the input stream, and this is called very early in page handling,
by the first reference to the

Form contents. But I'm not sure I'm reading this correctly. If I look at
Request.InputStream at PageLoad

time, it says that it is still at position 0. Does that mean that the
content really hasn't been streamed in

yet?

Also I wonder what I can trust. The simple thing is just to check
Request.ContentLength, but I assume that a

bad guy can just fake that to be a small number. Is the InputStream length a
real number that can be trusted?

Any suggestions would be appreciated.

--
...Mike
Jun 27 '08 #2
Hi Mike,

As for ASP.NET file uploading, so far when we get the chance to inspect the
Request's properties(such as content length or othe headers), the post
data(form entries or binary content if use mult-part form) should have been
transmit to server-side. And the ASP.NET maxRequestLength and it's too late
to prevent uploading large size data. The ASP.NET maxRequestLength should
be checking the upload stream size a bit ealier, but still can only detect
the problem after the certain size of data(of the maxRequestLength) has
been uploaded to server. So far I'm afraid there hasn't any good approach
for web page based upload program since we haven't much control at the
client-side(such as checking the file size before posting/uploading). If
some rich client based component is allowed for your scenario, you may
consider using some ActiveX or IE hosted .NET control to perform file
upload since that can check file size in advance.

BTW, for setting <httpRuntime ....for different pages, you can also use
the <locationelement in web.config instead of putting different pages
into different sub folders:

#location Element (ASP.NET Settings Schema)
http://msdn2.microsoft.com/en-us/library/b6x6shw7.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: =?Utf-8?B?TWlrZSBLcmFsZXk=?= <mk*****@community.nospam>
Subject: Programmable limits on upload size
Date: Mon, 28 Apr 2008 18:27:20 -0700
>
In my ASP.NET application, I'd like to set limits on the maximum size of
an
>uploaded file. Normally I'd just

set the maxRequestLength of the httpRuntime element in web.config. But in
this case, I have a few different

aspx pages and I want the limit set differently for each. Yes, I could put
each in its own folder, each with

its own web.config, but that is rather awkward for this application.

Alternatively, I could leave the limit set in web.config to the largest
limit, and then in the other pages,

do my own checking, throwing an error if the ContentLength was too large.

But if the goal here is preventing a DOS attack on my server by someone
who
>is uploading lots of giant files,

maybe this is too late. That is, by the time my code gets to run, maybe
the
>content is already all uploaded

and has consumed the server resources. I'd rather be able to stop things
earlier in the process.

Looking at some Reflector code, it appears that the method
Request.GetEntireRawContent is actually doing the

reading of the input stream, and this is called very early in page
handling,
>by the first reference to the

Form contents. But I'm not sure I'm reading this correctly. If I look at
Request.InputStream at PageLoad

time, it says that it is still at position 0. Does that mean that the
content really hasn't been streamed in

yet?

Also I wonder what I can trust. The simple thing is just to check
Request.ContentLength, but I assume that a

bad guy can just fake that to be a small number. Is the InputStream length
a
>real number that can be trusted?

Any suggestions would be appreciated.

--
...Mike
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
0
by: SEMIH DEMIR | last post by:
Sitelerden birinde verilen yabancı kaynakli bir scriptti duzenledim yanlız birseyin içinden bir turlu cıkamadım işin aslı ilk defa persistin upload componentini kullanacam yanlız suanki haliyle...
1
by: Marko Vuksanovic | last post by:
I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what...
6
by: Andrew Virnuls | last post by:
Hello all! We run a service for children who are off school for medical reasons, and we had a web-site that allows them to "submit" their work to teachers for marking. The site uses ASP code to...
1
by: walterbyrd | last post by:
If so, why? My webhoster, dreamhost, just informed me that my php apps can not upload files over 7mb, because of a PHP limitation. I don't know a lot about it, but I thought those limits were...
6
by: Bob Bedford | last post by:
Hi all, I've to resize uploaded images with the "imagecopyresampled" but when I've images quite large (common those days) I reach the 16mb limits of the ISP. How can I fix this ? I absolutely...
2
by: =?Utf-8?B?UGFycm90?= | last post by:
I get the message "Not enough space for the file on this disk" whenever I try to upload a jpg file using the FileUpload member in my web based C# program. I increased the requestMaximum file size...
16
by: Lawrence Krubner | last post by:
To guard against our users possibly uploading huge files, I've got this in my php.ini file: ; Maximum size of POST data that PHP will accept. post_max_size = 10M On a server running Ubuntu...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.