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
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