File Upload - httpRuntime maxRequestLength

  • Thread starter Thread starter Matt Chubb
  • Start date Start date
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
 
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)
 
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,
 
Is there no way IIS can handle this and redirect to a custom error page
configured by us?

Thanks

Matt
 
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,
 
Is there a soultion for this???
Will it work on WinServer 2003 ???
Is there an patch???

Thanks

Mirek
 

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

Back
Top