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.)