FileUp provides two different means for limiting the size of files or uploads that
are written to your webserver in the MaxBytes
and MaxBytesToCancel
settings.
If you look through the documentation, you will notice that MaxBytes
and MaxBytesToCancel
exist both as properties and as registry keys.
You should only set either the properties or the keys, but not both. Knowing when
to set the properties versus the registry keys is dependent on whether or not you
are using the HttpModule. Because the HttpModule caches the request before any ASP.NET
code is executed, the HttpModule must be informed of these settings via the registry.
Environment | How to Set the Values |
---|---|
ASP | Set values as FileUp Properties |
ASP.NET, using the HttpModule | Set values as Registry Keys |
ASP.NET, without the HttpModule (not recommended) |
Same as for ASP |
The MaxBytes registry setting specifies the maximum number of bytes on a per file basis that the HttpModule will write to disk before passing on the request for further processing. This means that files will be truncated at the size specified in the MaxBytes setting. No errors will be raised by FileUp when this occurs. Setting this key to 0 disables MaxBytes, and this is the default value. When using ASP or ASP.NET without the HttpModule, use the MaxBytes property of the FileUp object. When using the HttpModule, you must use this registry setting instead, since the HttpModule processes the request before the ASP.NET script is executed.
Specifies the maximum size in bytes of the entire Request before the HttpModule will abort the Request. Setting this key to 0 disables MaxBytesToCancel, and this is the default value. When using ASP or ASP.NET without the HttpModule, use the MaxBytesToCancel property of the FileUp object. When using the HttpModule, you must use this registry setting instead, since the HttpModule processes the request before the ASP.NET script is executed.
Both of these settings are stop-gap measures that can be employed to protect your webserver from certain types of attacks; however, used alone, they are not ideal for providing a user-friendly experience to legitimate users. The following suggestions might be employed to provide a better interaction with your end user:
TotalBytes
property
of the File
object can be used to test for any files that are the same
size as your MaxBytes property. A message can be sent to the user that the file
has been truncated, or the file can be deleted from the webserver with the File
object's delete
method. C# |
---|
//--- Get a reference to the uploaded file field
|
VB.NET |
'--- Get a reference to the uploaded file field
|