Connecting Tech Pros Worldwide Help | Site Map

File Upload - httpRuntime maxRequestLength

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 6th, 2005, 01:55 PM
Matt Chubb
Guest
 
Posts: n/a
Default File Upload - httpRuntime maxRequestLength

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



  #2  
Old December 6th, 2005, 04:39 PM
Bruce Barker
Guest
 
Posts: n/a
Default 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]


  #3  
Old December 6th, 2005, 08:35 PM
Joerg Jooss
Guest
 
Posts: n/a
Default 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
  #4  
Old December 7th, 2005, 09:45 AM
Matt Chubb
Guest
 
Posts: n/a
Default 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]


  #5  
Old December 7th, 2005, 05:25 PM
Joerg Jooss
Guest
 
Posts: n/a
Default 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
  #6  
Old December 21st, 2005, 01:25 PM
Mirek Endys
Guest
 
Posts: n/a
Default 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]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.