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

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.maxRequestLength has been exceeded and
2. when the uploaded file is under then httpRuntime.maxRequestLength
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 4901
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_Error. Your code should look something like this:

<script runat="server">
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim currentException As Exception
currentException = Server.GetLastError.GetBaseException()
Response.Redirect("/error.aspx?Err=" &
Server.UrlEncode(currentException.Message))
End Sub
</script>

The application_Error 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**@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi

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

1. when the httpRuntime.maxRequestLength has been exceeded and
2. when the uploaded file is under then httpRuntime.maxRequestLength
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_Error 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 maxRequestLength, 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="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="ValidateFileSizeInC.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="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function GetSize(path)
{
var fso, f1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1=fso.GetFile(path);
return f1.Size;
}

function CheckSize() {
var size=GetSize(Form1.myFile.value);
if (size 10240) {
alert("File is too big");
window.event.returnValue = false;
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server"
enctype="multipart/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><INPUT 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(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Button1.Attributes.Add("onclick", "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
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
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...
6
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...
4
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...
6
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...
2
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
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"...
5
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...
1
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.