Response Redirection on Callback Exceptions
- 4 minutes to read
When an unhandled exception occurs during server-side callback processing, the ASPxHttpHandlerModule prevents an application from becoming unresponsive by sending a specific response to the client. Specify the required page name in the Web.Config file’s Redirection on a Callback Error option to redirect the response to a page that displays error information – as shown below.
<configuration>
...
<devExpress>
...
<errors callbackErrorRedirectUrl="~/Error.aspx" />
</devExpress>
</configuration>
Note that the callbackErrorRedirectUrl property value should contain the subdirectory name (if it requires) and have the following format:
/subdir/Home/Error
Note
MVC-Specific Note The callbackErrorRedirectUrl property value should contain a subdirectory name (“/{sub-directory}/Home/Error”) if a MVC application’s root URL meets the following conditions:
- The URL is overridden using the IIS Web Server.
- The URL contains a subdirectory (for example, “http://localhost/{sub-directory}”).
Typically, the page to which the response is redirected shows information about the server exception. Use the static ASPxWebControl.GetCallbackErrorMessage method while the page redirect is processed, to obtain exception-related information. For example, you can execute the code below on page load.
using DevExpress.Web.ASPxClasses;
public partial class Error : Page {
protected void Page_Load(object sender, EventArgs e) {
string errorMessage = ASPxWebControl.GetCallbackErrorMessage();
Response.Output.Write(errorMessage);
}
}
Example
In this example, the error message is displayed within the redirected page (Error.aspx) after an exception occurs on a callback within the Default.aspx page.
The redirection page is specified within the devExpress -> errors section of the web.config file via the callbackErrorRedirectUrl key (see Redirection on a Callback Error). The error message is obtained by using the static ASPxWebControl.GetCallbackErrorMessage method.
Note
To provide the message redirection between pages, the ASPxHttpHandlerModule should be registered within the web.config file.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-get-the-error-message-by-using-the-getcallbackerrormessage-static-method-e1988
- Default.aspx (C#)
- Default.aspx.cs
- Error.aspx (C#)
- Error.aspx.cs
- Error.aspx (VB.NET)
- Default.aspx.vb
- Default.aspx (VB.NET)
- Error.aspx.vb
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v10.1" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v10.1" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<dx:ASPxButton id="ASPxButton1" runat="server" AutoPostBack="False" text="Perform Callback">
<ClientSideEvents Click="function(s, e) { callback1.PerformCallback(); }"></ClientSideEvents>
</dx:ASPxButton>
<dx:ASPxCallback ID="ASPxCallback1" runat="server" ClientInstanceName="callback1"></dx:ASPxCallback>
</form>
</body>
</html>