Skip to main content
A newer version of this page is available. .

Handling Callback Exceptions on Server

  • 7 minutes to read

You can use the static ASPxWebControl.CallbackError event to delegate callback exception handling to the Application_Error event handler (via the Web Application project’s Global.asax file), so that it handles all application-level errors (e.g., to log information on all errors). In the Global.asax file, add the following code to the Application_Start event handler. (Note that prior to version v10.2 of DevExpress ASP.NET controls, errors occurring on callback events could not be handled via the Application_Error event handler.)

void Application_Start(object sender, EventArgs e) { 
    // Assign Application_Error as a callback error handler for DevExpress web controls
    ASPxWebControl.CallbackError += new EventHandler(Application_Error); 
} 

Use the following code within the Application_Error event handler to obtain and log exception details:

void Application_Error(object sender, EventArgs e) { 
    // ... 
    // Use HttpContext.Current to get a Web request processing helper 
    HttpServerUtility server = HttpContext.Current.Server; 
    Exception exception = server.GetLastError(); 
    // Log an exception 
    AddToLog(exception.Message, exception.StackTrace); 
}

Example

This example demonstrates how the ASPxWebControl.CallbackError server static event can be used within the Global.asax file to delegate handling of exceptions that occur during processing of DevExpress web control callbacks to the Application_Error event handler.

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="devExpress">
      <section name="themes" type="DevExpress.Web.ThemesConfigurationSection, DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="compression" type="DevExpress.Web.CompressionConfigurationSection, DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="settings" type="DevExpress.Web.SettingsConfigurationSection, DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="errors" type="DevExpress.Web.ErrorsConfigurationSection, DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="DevExpress.Data.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
        <add assembly="DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
        <add assembly="DevExpress.Printing.v14.2.Core, Version=14.2.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>
    <pages validateRequest="false">
    </pages>
    <customErrors redirectMode="ResponseRedirect" defaultRedirect="~/ErrorPage.aspx" mode="On">
      <error statusCode="500" redirect="~/ErrorPage.aspx" />
    </customErrors>
    <httpModules>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
    </httpModules>
    <httpHandlers>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" validate="false" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <modules>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode" />
    </handlers>
  </system.webServer>
  <devExpress>
    <themes enableThemesAssembly="true" styleSheetTheme="" theme="" customThemeAssemblies="" />
    <compression enableHtmlCompression="false" enableCallbackCompression="true" enableResourceCompression="true" enableResourceMerging="true" />
    <settings doctypeMode="Xhtml" rightToLeft="false" embedRequiredClientLibraries="false" ieCompatibilityVersion="edge" />
    <errors callbackErrorRedirectUrl="~/ErrorPage.aspx" />
  </devExpress>
</configuration>
See Also