Problem with Upload Error handling

Discussion in 'ASP .Net' started by =?Utf-8?B?SG9seXNtb2tl?=, Aug 28, 2007.

  1. 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
    =?Utf-8?B?SG9seXNtb2tl?=, Aug 28, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?SG9seXNtb2tl?=

    Patrice Guest

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

    ---
    Patrice

    "Holysmoke" <> a écrit dans le message de
    news: ...
    > 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
    Patrice, Aug 28, 2007
    #2
    1. Advertising

  3. =?Utf-8?B?SG9seXNtb2tl?=

    bruce barker Guest

    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)

    Holysmoke wrote:
    > 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
    bruce barker, Aug 28, 2007
    #3
  4. 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

    "bruce barker" wrote:

    > 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)
    >
    > Holysmoke wrote:
    > > 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

    >
    =?Utf-8?B?SG9seXNtb2tl?=, Aug 29, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Smith
    Replies:
    14
    Views:
    772
    Al Smith
    Feb 16, 2004
  2. =?Utf-8?B?U2FyYXY=?=

    Upload a file without file Upload control - ASP.Net

    =?Utf-8?B?U2FyYXY=?=, Aug 2, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,423
    Bruce Barker
    Aug 3, 2005
  3. Heather Fraser
    Replies:
    0
    Views:
    615
    Heather Fraser
    Jul 5, 2004
  4. J055
    Replies:
    3
    Views:
    1,311
    Steven Cheng[MSFT]
    Jul 5, 2006
  5. Replies:
    1
    Views:
    916
    Gabriel Genellina
    Nov 25, 2006
Loading...

Share This Page