File Upload - httpRuntime maxRequestLength 
December 6th, 2005, 02:55 PM
| | | |
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 | 
December 6th, 2005, 05:39 PM
| | | | 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] | 
December 6th, 2005, 09:35 PM
| | | | 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 | 
December 7th, 2005, 10:45 AM
| | | | 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] | 
December 7th, 2005, 06:25 PM
| | | | 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 | 
December 21st, 2005, 02:25 PM
| | | | 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] |  | | | | /bytes/about
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 225,698 network members.
|