473,836 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file upload maximum allowed size error handling

Hi

How do I tell the user he has tried to upload a file which is too big...

1. when the httpRuntime.max RequestLength has been exceeded and
2. when the uploaded file is under then httpRuntime.max RequestLength
For point 1. it would be good to at least display a nice error page. IE
seems to just display a blank page.
Thanks
Andrew

Jun 30 '06 #1
3 4937
There's a suggested workaround here that might be worth a try:

http://blog.hackedbrain.com/archive/...3/13/3860.aspx
"1. Create a global.asax file. If you're using Visual Studio 2005 it will
set up a number of common subroutines for you. You need to use Sub
Application_Err or. Your code should look something like this:

<script runat="server">
Sub Application_Err or(ByVal sender As Object, ByVal e As EventArgs)
Dim currentExceptio n As Exception
currentExceptio n = Server.GetLastE rror.GetBaseExc eption()
Response.Redire ct("/error.aspx?Err= " &
Server.UrlEncod e(currentExcept ion.Message))
End Sub
</script>

The application_Err or sub fires as a last resort, in other words, when you
haven't explicitly handled the exception anywhere else in your code. "

2. You can now create an error.aspx that displays the exception message
(from the querystring). For this exception the message is "Maximum request
length exceeded". You could also test for the message and give users more
information on the error.
"J055" <j0**@newsgroup s.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Hi

How do I tell the user he has tried to upload a file which is too big...

1. when the httpRuntime.max RequestLength has been exceeded and
2. when the uploaded file is under then httpRuntime.max RequestLength
For point 1. it would be good to at least display a nice error page. IE
seems to just display a blank page.
Thanks
Andrew

Jun 30 '06 #2
Hi Ken,

Thanks for your input.

However, as for the Application_Err or approach in the article you
mentioned, have you ever tried it in some test applications? Based on my
experience, this is not guaranteed to work since when the uploading data
exceed the ASP.NET httpRuntime maxRequestLengt h, the runtime will directly
stop the worker thread and close the connection, thereforce any sequential
exception handler code has no chance to be executed. That's also why we
generally will see a "server not found ..." error page(like a connection
issue).

Hi Andrew,

I'm afraid this is a tough issue for ASP.NET large file uploading. As I
mentioned above, the maxRequestLengh exceeding exception will close the
underlying tcp/http socket connection that cause the seqential error
handling code unable to get executed. I've ever met some other customers
discussing on this issue and have also discussed with some IIS engineers,
so far we may consider the following approachs if we do care about the file
size validating or controlling:

1. We can use some rich client-side scripts to validate the size of the
file (user has chosen). Here is a sample page:
=============== =============== =============== ====
=============== ==========
<%@ Page language="c#" Codebehind="Web Form1.aspx.cs"
AutoEventWireup ="false"
Inherits="Valid ateFileSizeInC. WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1 </title>
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR " Content="Micros oft Visual Studio 7.0">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<script language="javas cript">
function GetSize(path)
{
var fso, f1;
fso = new ActiveXObject(" Scripting.FileS ystemObject");
f1=fso.GetFile( path);
return f1.Size;
}

function CheckSize() {
var size=GetSize(Fo rm1.myFile.valu e);
if (size 10240) {
alert("File is too big");
window.event.re turnValue = false;
}
}
</script>
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server"
enctype="multip art/form-data">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 29px; POSITION:
absolute; TOP:
33px" runat="server"> Enter File Name:</asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 35px; POSITION:
absolute;
TOP: 105px" runat="server"
Text="Upload"></asp:Button><INP UT style="Z-INDEX: 103; LEFT: 32px;
POSITION:
absolute; TOP: 64px" type="file" id="myFile"
runat="server">
</form>
</body>
</HTML>

=============== =========

And in the code behind:

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
Button1.Attribu tes.Add("onclic k", "CheckSize();") ;
}

=============== ====
=============== =============== =========
2. For rich and powerful file uploading, you can also consider use some
rich client components such as activex control or IE hosted .net
usercontrol to update the file from client to server. In such cases, the
error and exception handling could be done in these rich client control's
codelogic.

Hope this helps some. Thanks for your understanding.

Regards,

Steven Cheng

Microsoft MSDN Online Support Lead
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Jul 3 '06 #3
Hi Andrew,

How are you doing on this issue? Or does our suggestion in the former reply
helps you some? Please feel free to post here if there is anything else we
can help.

Regards,

Steven Cheng
Microsoft MSDN Online Support Lead
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 5 '06 #4

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

Similar topics

3
2192
by: Mike Walsh | last post by:
I have a problem uploading files with PHP which has me stumped! I am unable to successfully upload files. My simple test script is as follows: <?php if (count($_FILES)) { var_dump($_FILES) ; }
1
2211
by: Jonathan | last post by:
Hi everyone, I have a problem with the file uploading in Asp.Net and I have read a lot on forums on this but never found an answer. Here is the problem: I know Asp.Net maximum Length for uploading a file to the server is 4Mo but I changed that maximum to about 10Mo in my web.config file : <httpRuntime executionTimeout="45" maxRequestLength="10000" useFullyQualifiedRedirectUrl="true" />
6
4854
by: Thomas Due | last post by:
Hi, I am writing an ASP.NET project where I allow users to upload files to the server. I have changed to web.config to allow a total file size of 100MB. My problem is that if the total file size exceed this amount the page simply stops works, and I get a "Server unreachable" error. Is there any way to handle this, so I am able to present the user with a nice error message telling him that the maximum file size has been exceeded.
4
4418
by: news microsoft | last post by:
Hello all, In my ASP.Net , C# web Application I have used the traditional upload code i.e. HTTP Method and it works fine for files and images up to 5 MB but once the size of file is more than 5 MB it gives a error mostly time out error and also uploading sound files (.mp3, .wma, .dat) is not allowed.
6
4141
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page comes back with all the data intact, except for the upload object. The text box for "MyFile" (my example) is always cleared. Why is that and is there a way to stop that from happening? Thanks,
2
2290
by: yonthebeach | last post by:
hi, i have an upload mechanism on my website and want to check the filesize on the client size. is this possible? thanks yavuz bogazci
1
6518
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
5
6818
by: kailashchandra | last post by:
I am trying to upload a file in php,but it gives me error msg please Help me? My Code is like below:- i have one php file named upload.php and i have another html file named upload.html and inside html i am calling php file upload.php:- <?php
1
47507
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9671
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10854
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10558
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10600
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.