By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Catching Exception for "Maximum request length exceeded"

P: n/a
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB so
that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for HttpException,
apparrently I'm not smart enough to know where this goes or to find any kind
of useful article on the subject (all the ones I have found, don't address
what I am trying to do, and worse yet don't give any real clear examples
just vague descriptions).

Thanks,

Chris

Nov 19 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
I figured it out...

I placed the code to handle it in the Application_Error method of the
global.asax file... I tend to overlook the global.asax nowadays...

Chris
"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config
file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB so
that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for
HttpException, apparrently I'm not smart enough to know where this goes or
to find any kind of useful article on the subject (all the ones I have
found, don't address what I am trying to do, and worse yet don't give any
real clear examples just vague descriptions).

Thanks,

Chris

Nov 19 '05 #2

P: n/a
I figured it out...

I placed the code to handle it in the Application_Error method of the
global.asax file... I tend to overlook the global.asax nowadays...

Chris
"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config
file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB so
that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for
HttpException, apparrently I'm not smart enough to know where this goes or
to find any kind of useful article on the subject (all the ones I have
found, don't address what I am trying to do, and worse yet don't give any
real clear examples just vague descriptions).

Thanks,

Chris

Nov 19 '05 #3

P: n/a
Anyone have any other ideas? Because I am out of ideas now.

Chris
"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config
file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB so
that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for
HttpException, apparrently I'm not smart enough to know where this goes or
to find any kind of useful article on the subject (all the ones I have
found, don't address what I am trying to do, and worse yet don't give any
real clear examples just vague descriptions).

Thanks,

Chris

Nov 19 '05 #4

P: n/a
Anyone have any other ideas? Because I am out of ideas now.

Chris
"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config
file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB so
that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for
HttpException, apparrently I'm not smart enough to know where this goes or
to find any kind of useful article on the subject (all the ones I have
found, don't address what I am trying to do, and worse yet don't give any
real clear examples just vague descriptions).

Thanks,

Chris

Nov 19 '05 #5

P: n/a
http://www.developer.com/db/print.php/10920_3426051_2
"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config
file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB so
that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for
HttpException, apparrently I'm not smart enough to know where this goes or
to find any kind of useful article on the subject (all the ones I have
found, don't address what I am trying to do, and worse yet don't give any
real clear examples just vague descriptions).

Thanks,

Chris

Nov 19 '05 #6

P: n/a
http://www.developer.com/db/print.php/10920_3426051_2
"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config
file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB so
that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for
HttpException, apparrently I'm not smart enough to know where this goes or
to find any kind of useful article on the subject (all the ones I have
found, don't address what I am trying to do, and worse yet don't give any
real clear examples just vague descriptions).

Thanks,

Chris

Nov 19 '05 #7

P: n/a
Hi, Chris.

This should work...

In global.asax :
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("Errors.aspx")
End Sub

The "errors.aspx" :
----------------------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException, HttpException)
Select Case checkException.GetHttpCode
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" & appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>Please contact the server's administrator."
Server.ClearError()
End Sub
</script>

<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true" runat=server/>
<hr>
</body>
</html>

--------------------

You can embellish that a bit, or add info ( like an email address )
and I'm sure you can improve on that basic structure, but at least
this handler works when an httpException is thrown.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message news:uu**************@tk2msftngp13.phx.gbl...
Anyone have any other ideas? Because I am out of ideas now.

Chris


"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config
file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB so
that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for
HttpException, apparrently I'm not smart enough to know where this goes or
to find any kind of useful article on the subject (all the ones I have
found, don't address what I am trying to do, and worse yet don't give any
real clear examples just vague descriptions).

Thanks,

Chris


Nov 19 '05 #8

P: n/a
Hi, Chris.

This should work...

In global.asax :
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("Errors.aspx")
End Sub

The "errors.aspx" :
----------------------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException, HttpException)
Select Case checkException.GetHttpCode
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" & appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>Please contact the server's administrator."
Server.ClearError()
End Sub
</script>

<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true" runat=server/>
<hr>
</body>
</html>

--------------------

You can embellish that a bit, or add info ( like an email address )
and I'm sure you can improve on that basic structure, but at least
this handler works when an httpException is thrown.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message news:uu**************@tk2msftngp13.phx.gbl...
Anyone have any other ideas? Because I am out of ideas now.

Chris


"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config
file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB so
that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for
HttpException, apparrently I'm not smart enough to know where this goes or
to find any kind of useful article on the subject (all the ones I have
found, don't address what I am trying to do, and worse yet don't give any
real clear examples just vague descriptions).

Thanks,

Chris


Nov 19 '05 #9

P: n/a
Chris,

Just add this case to the code I just sent you
in the "Well global.asax didn't work as well as hoped" thread :

Case 400
errMessage &= "Bad request. The file size is too large."

That will work fine for what you want to do.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
http://www.developer.com/db/print.php/10920_3426051_2
"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config file.

And now I am trying to CATCH the "Maximum request length exceeded" HttpException when a
user tries to send a file that is greater than 2MB so that I may tell the user,
gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for HttpException,
apparrently I'm not smart enough to know where this goes or to find any kind of useful
article on the subject (all the ones I have found, don't address what I am trying to
do, and worse yet don't give any real clear examples just vague descriptions).

Thanks,

Chris


Nov 19 '05 #10

P: n/a
Chris,

Just add this case to the code I just sent you
in the "Well global.asax didn't work as well as hoped" thread :

Case 400
errMessage &= "Bad request. The file size is too large."

That will work fine for what you want to do.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
http://www.developer.com/db/print.php/10920_3426051_2
"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config file.

And now I am trying to CATCH the "Maximum request length exceeded" HttpException when a
user tries to send a file that is greater than 2MB so that I may tell the user,
gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for HttpException,
apparrently I'm not smart enough to know where this goes or to find any kind of useful
article on the subject (all the ones I have found, don't address what I am trying to
do, and worse yet don't give any real clear examples just vague descriptions).

Thanks,

Chris


Nov 19 '05 #11

P: n/a
Thanks Juan,

I tried what you provided and it worked up to a point, and then all kinds of
problems occurred again. It's not because of the code, it's because of how
ASP.NET handles Requests that exceed the maximum size.

I finally went with setting a custom error page for HTTP 400 (Request
exceeds maximum length). It doesn't allow me to do everything I want, but at
least it handles the error more gracefully.

Thanks again,

Chris

PS
I'm going to keep working on this (probably off and on). I want a more user
friendly handler for HTTP 400.
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Chris,

Just add this case to the code I just sent you
in the "Well global.asax didn't work as well as hoped" thread :

Case 400
errMessage &= "Bad request. The file size is too large."

That will work fine for what you want to do.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
http://www.developer.com/db/print.php/10920_3426051_2
"Chris Hayes" <cp.hayes@[NO2SPAM]sbcglobal.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have an ASP.NET page that accepts input from an HtmlInputFile object.

I have set the maximum size for HttpRequests to 2MB in the web.config
file.

And now I am trying to CATCH the "Maximum request length exceeded"
HttpException when a user tries to send a file that is greater than 2MB
so that I may tell the user, gracefully, that their file is too big.

Now, my question is where in the world do I add a Handler for
HttpException, apparrently I'm not smart enough to know where this goes
or to find any kind of useful article on the subject (all the ones I
have found, don't address what I am trying to do, and worse yet don't
give any real clear examples just vague descriptions).

Thanks,

Chris



Nov 19 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.