Problem with Upload Error handling

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Problem with Upload Error handling

When the user uploads the file greater than the length specified in
web.config/machine.config, I always see the DNS Error page eventhough I have
handled the error Page_Error Event.

And this is my code in Page_Error event,


Private Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Error

Dim ex As Exception = Server.GetLastError.GetBaseException

If TypeOf (ex) Is HttpException Then

Dim oEx As HttpException = CType(ex, HttpException)
If oEx.ErrorCode = -2147467259 Then
Dim ErrorLabel As New Label
ErrorLabel.ForeColor = System.Drawing.Color.Red
ErrorLabel.Text = "La dimensione del file supera la
dimensione massima consentita di 4MB"
Dim oCell As New HtmlTableCell
oCell.Controls.Add(ErrorLabel)
trUpload.Cells.Add(oCell)
Server.ClearError()
Response.ClearHeaders()
Response.Status = "200 OK"
Response.End()
Else
Throw New ApplicationException(oEx.Message, oEx)
End If
Else
Throw New ApplicationException(ex.Message, ex)
End If

End Sub


I tried to set later just to get rid of DNS Error

Response.Status = "200 OK"
Response.End()

But in vain.

Can anyone shed some light on this? Why so Response.Status does not work?

TIA,
Holy
 
IMO the problem is that this check is done before your page even loads. You
should be able to catch this in the Application-Error event rather than in
the Page_Error event...
 
there is no cancel upload command the server can send, so when the
upload is too big, the server closes the connection. this means the
server can not send back a response, and the browser displays failed
request error (dns in IE)

-- bruce (sqlwork.com)
 
I solved this problem by setting maxrequestlength to 10 MB, but via code I
check for my Quota (say 5MB). I suppose this is only way to get rid of this
problem. Correct me if I am wrong. This workaround also fails if the user
tries to upload the file > 10 MB.

Thanks all,
Holy
 
Back
Top