This is a migrated thread and some comments may be shown as answers.

Problem with centralized error handling, Application_Error

2 Answers 127 Views
Compression
This is a migrated thread and some comments may be shown as answers.
Caesar
Top achievements
Rank 1
Caesar asked on 19 May 2011, 01:37 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Pavel
Telerik team
answered on 20 May 2011, 08:53 AM
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.

0
Caesar
Top achievements
Rank 1
answered on 20 May 2011, 12:59 PM
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
Tags
Compression
Asked by
Caesar
Top achievements
Rank 1
Answers by
Pavel
Telerik team
Caesar
Top achievements
Rank 1
Share this question
or