By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,312 Members | 1,341 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,312 IT Pros & Developers. It's quick & easy.

File Upload - httpRuntime maxRequestLength

P: n/a
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("Work erRequest",
(BindingFlags)36).GetValue(cxt, null);

if(cxt.Request.ContentType.IndexOf("multipart/form-data") > -1)
{
int intContentLength =
Convert.ToInt32(hwr.GetKnownRequestHeader(HttpWork erRequest.HeaderContentLength));
if(intContentLength > 3072000)
{
app.Context.Response.Redirect("FileSizeException.a spx");
}
}
}
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
Dec 6 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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)

"Matt Chubb" <ma***********@4cassociates.com> wrote in message
news:e$******************@TK2MSFTNGP15.phx.gbl...
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("Work erRequest",
(BindingFlags)36).GetValue(cxt, null);

if(cxt.Request.ContentType.IndexOf("multipart/form-data") > -1)
{
int intContentLength =
Convert.ToInt32(hwr.GetKnownRequestHeader(HttpWork erRequest.HeaderContentLength));
if(intContentLength > 3072000)
{
app.Context.Response.Redirect("FileSizeException.a spx");
}
}
}
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

Dec 6 '05 #2

P: n/a
Bruce Barker wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Dec 6 '05 #3

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

Thanks

Matt

"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:xn****************@msnews.microsoft.com...
Bruce Barker wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Dec 7 '05 #4

P: n/a
Matt Chubb wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Dec 7 '05 #5

P: n/a
Is there a soultion for this???
Will it work on WinServer 2003 ???
Is there an patch???

Thanks

Mirek

"Bruce Barker" <br******************@safeco.com> wrote in message
news:OB****************@TK2MSFTNGP11.phx.gbl...
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)

"Matt Chubb" <ma***********@4cassociates.com> wrote in message
news:e$******************@TK2MSFTNGP15.phx.gbl...
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("Work erRequest",
(BindingFlags)36).GetValue(cxt, null);

if(cxt.Request.ContentType.IndexOf("multipart/form-data") > -1)
{
int intContentLength =
Convert.ToInt32(hwr.GetKnownRequestHeader(HttpWork erRequest.HeaderContentLength));
if(intContentLength > 3072000)
{
app.Context.Response.Redirect("FileSizeException.a spx");
}
}
}
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


Dec 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.