Problem with centralized error handling, Application_Error

3 posts, 1 answers
  1. Caesar
    Caesar avatar
    59 posts
    Member since:
    Aug 2008

    Posted 19 May 2011 Link to this post

    Hi,

    We have done the following:
    In Appliction_Error and in ScriptManager_AsyncPostBackError, we handle and logs the exception.
    Then we redirect to an error page.

    When not using radcompression, this works for all cases, but when using radcompression, the redirect doesn't happen when an exception occurs in Page_PreInit. The exception must also be in an Async callback, normal postbacks works as expected.

    Default.aspx:
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="default.aspx.vb" Inherits="WebApplication8._default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="upError" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Button ID="btnError" runat="server" Text="Error" />
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:Button ID="btnErrorNoUpdatePanel" runat="server" Text="ErrorNoUpdatePanel" />
        </div>
        </form>
    </body>
    </html>

    Default.aspx.vb:
    Public Class _default
        Inherits System.Web.UI.Page
     
        Private Sub _default_PreInit(sender As Object, e As System.EventArgs) Handles Me.PreInit
            If Me.IsPostBack Then
                Throw New Exception("Test")
            End If
        End Sub
     
        Private Sub sm_AsyncPostBackError(sender As Object, e As System.Web.UI.AsyncPostBackErrorEventArgs) Handles sm.AsyncPostBackError
            Server.ClearError()
            Response.Redirect("Error.aspx")
        End Sub
    End Class

    Error.aspx:
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Error.aspx.vb" Inherits="WebApplication8._Error" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            An error occured!
        </div>
        </form>
    </body>
    </html>

    web.config:
    <?xml version="1.0"?>
    <configuration>
        <system.web>
            <customErrors mode="Off"/>
            <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
            <httpModules>
                <add name="RadCompression" type="Telerik.Web.UI.RadCompression"/>
            </httpModules>
        </system.web>
        <system.webServer>
            <modules runAllManagedModulesForAllRequests="true">
                <remove name="RadCompression" />
                <add name="RadCompression" preCondition="managedHandler" type="Telerik.Web.UI.RadCompression"/>
            </modules>
        </system.webServer>
    </configuration>

    Global.asax.vb:
    Imports System.Web.SessionState
     
    Public Class Global_asax
        Inherits System.Web.HttpApplication
     
        Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
            ' Fires when an error occurs
            Server.ClearError()
            Response.Redirect("Error.aspx")
        End Sub
     
    End Class

    When hitting the Error-button, I don't get to the error page, but when hitting the ErrorNoUpdatePanel I do get to the error page.
    If turning off RadCompression both cases works.

    Regards
    Caesar
  2. Answer
    Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 20 May 2011 Link to this post

    Hi Caesar,

    Calling Response.Redirect() at such late stage causes an exception as the appropriate response header cannot be added nor changed. As a result this prevents adding the compression content-encoding header and the browser is not able to decode the response from the server. As a workaround I can suggest you to call the Redirect() in the OnError handler of the Page.

    Best wishes,
    Pavel
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Caesar
    Caesar avatar
    59 posts
    Member since:
    Aug 2008

    Posted 20 May 2011 Link to this post

    Hi,

    Thanks, that works fine for this case, still have to keep the error handling in Application_Error for other reasons (when not a page), but that is OK.

    Regards
    Caesar
Back to Top