File Upload - httpRuntime maxRequestLength

M

Matt Chubb

I've searched the forums and the net and have not found a solution to this
upload problem, any suggestions/help in this matter would be greatly
appreciated.

I'm trying to trap and display an appropriate error message when a file
upload is more than the maxRequestLength of the httpRuntime tag within
web.config/machine.config and prevent the "Page Cannot be Displayed" error
message appearing and the ASP.NET worker process bombing out (Doesn't look
particularly pretty to the user).

I've tried creating an UploadHandler, which inherits IHttpModule and runs a
custom BeginRequest handler containing the following code snippet, which in
theory should work:

try
{
HttpApplication app = (HttpApplication)sender;
HttpContext cxt = app.Context;
HttpWorkerRequest hwr =
(HttpWorkerRequest)cxt.GetType().GetProperty("WorkerRequest",
(BindingFlags)36).GetValue(cxt, null);

if(cxt.Request.ContentType.IndexOf("multipart/form-data") > -1)
{
int intContentLength =
Convert.ToInt32(hwr.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength));
if(intContentLength > 3072000)
{
app.Context.Response.Redirect("FileSizeException.aspx");
}
}
}
catch(Exception ex)
{

}

This code functions as it should, but does not perform the redirect and
displays the "Page Cannot be Displayed" error message, due to the same
reason as discussed earlier.

I apologise for the intense post, but I would really like to find a solution
to this problem or any comments anyone has regarding this issue.

Thanks in advance

Matt
 
B

Bruce Barker

the problem is the http 1.1 protocol. there is no server message to stop the
upload (browser request). so when the max length is hit, asp.net closes the
request stream to stop the upload. this of course causes the browser to
display the error.

-- bruce (sqlwork.com)
 
J

Joerg Jooss

Bruce said:
the problem is the http 1.1 protocol. there is no server message to
stop the upload (browser request). so when the max length is hit,
asp.net closes the request stream to stop the upload. this of course
causes the browser to display the error.

Quite the contrary, HTTP 1.1 is the solution -- at least in theory. If
the client would send an Expect: Continue header, the server would be
able to reject an oversized upload with a 417 reponse.

Cheers,
 
M

Matt Chubb

Is there no way IIS can handle this and redirect to a custom error page
configured by us?

Thanks

Matt
 
J

Joerg Jooss

Matt said:
Is there no way IIS can handle this and redirect to a custom error
page configured by us?

Probably by implementing something at the ISAPI level, but I'm no
expert here :-/

Cheers,
 
M

Mirek Endys

Is there a soultion for this???
Will it work on WinServer 2003 ???
Is there an patch???

Thanks

Mirek
 
Joined
Aug 17, 2006
Messages
2
Reaction score
0
Any fix on this guys? searching high and low for a solution and 5 hours in with a lot of anticipation. Please help with a url or text for this solution!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top