Connecting Tech Pros Worldwide Help | Site Map

File Upload - httpRuntime maxRequestLength

Matt Chubb
Guest
 
Posts: n/a
#1: Dec 6 '05
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


Bruce Barker
Guest
 
Posts: n/a
#2: Dec 6 '05

re: File Upload - httpRuntime maxRequestLength


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" <matthew.chubb@4cassociates.com> wrote in message
news:e$Y%23SNn%23FHA.2464@TK2MSFTNGP15.phx.gbl...[color=blue]
> 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
>
>[/color]


Joerg Jooss
Guest
 
Posts: n/a
#3: Dec 6 '05

re: File Upload - httpRuntime maxRequestLength


Bruce Barker wrote:
[color=blue]
> 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.[/color]

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:news-reply@joergjooss.de
Matt Chubb
Guest
 
Posts: n/a
#4: Dec 7 '05

re: File Upload - httpRuntime maxRequestLength


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

Thanks

Matt



"Joerg Jooss" <news-reply@joergjooss.de> wrote in message
news:xn0eaohzs3fk5ek007@msnews.microsoft.com...[color=blue]
> Bruce Barker wrote:
>[color=green]
>> 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.[/color]
>
> 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:news-reply@joergjooss.de[/color]


Joerg Jooss
Guest
 
Posts: n/a
#5: Dec 7 '05

re: File Upload - httpRuntime maxRequestLength


Matt Chubb wrote:
[color=blue]
> Is there no way IIS can handle this and redirect to a custom error
> page configured by us?[/color]

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

Cheers,
--
http://www.joergjooss.de
mailto:news-reply@joergjooss.de
Mirek Endys
Guest
 
Posts: n/a
#6: Dec 21 '05

re: File Upload - httpRuntime maxRequestLength


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

Thanks

Mirek

"Bruce Barker" <brubar_nospamplease_@safeco.com> wrote in message
news:OBDE$qo%23FHA.2324@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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" <matthew.chubb@4cassociates.com> wrote in message
> news:e$Y%23SNn%23FHA.2464@TK2MSFTNGP15.phx.gbl...[color=green]
>> 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
>>
>>[/color]
>
>[/color]


Closed Thread