maxRequestLength and Trap Page Not Found error

S

sam

Hi,

I have seen many posts about this problem and no resolution.

I have set the maxRequestLength to 200K as I don't want anyone
uploading files to the server greater than this size.

I have put code into Application_BeginRequest and Application_Error to
try and trap the error of "Page Not Found". Nothing seems to stop the
inevitable of the browser going to the "Page Not Found" page. I have
even put in the web.config custom errors, trapping the 404 error and
also set a defaultRedirect. None of this has any difference.

In Application_BeginRequest I have:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
// stop the page continuing if the post is greater than 300K (this
// caters any text uploaded with the form submit
if (Context.Request.ContentLength > 300000)
{
Response.Clear();
Response.Redirect("ErrorPage.aspx", true);
}
}

It does break into here, and it does run the Response.Redirect
command, yet.. I am still re-directed to the Page Not found page. I
have breakpoints everywhere and no matter where I try to trap the
error, it still goes to the Page not found page. Even tried using
Page_Error on the page where the upload is taking place.

Has anyone got any further ideas? I have searched Google over and over
and everyone seems to have the same problem but with no solutions. :|

Thanks,
Sam
 
B

bruce barker

there is no solution. the http protocol has no support for stopping a file
upload and returning an error. the only way asp.net can stop the upload is
to close the connection when the max size is reached. this causes a network
error at the browser, and the browser displays the error message of its
choice - generally page not found because it the request for page never
completed.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top