[DevExpress Support Team: CLONED FROM T295187: UploadControl - Uploading an empty file into Azure results in the "BadRequest RequestResult: InvalidHeaderValueThe value for one of the HTTP headers is not in the correct format." error]
Hi,
I tried your solution to update the error message but the Application_Error would not get hit on a CallbackError.
When I try to upload an empty file with a breakpoint in the Application_Error method, the breakpoint will not get hit and the message will stay as it originally was.
I would upload a demo project but it won't let me upload a file more than 30MB
CallbackError event handler is not invoked on a callback error
Answers approved by DevExpress Support
Hello,
In order to override callback error messages or handle callback exceptions in the required manner, set the ASPxWebControl.CallbackError event handler.
In this handler, determine the type of the exception and override the default exception handling process. For example:
- When you are trying to upload a file and there is an exception on the server side, the exception message is not informative enough or gives a user too much technical info.
C#public static void FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) {
throw new Exception("CallbackException. Some error message you want to override!");
}
- When you set the ASPxWebControl.CallbackError event handler, you are able to override the default callback handling behavior. You can, for example, change the callback error message using ASPxWebControl.SetCallbackErrorMessage.
C#protected void Application_Start() {
...
DevExpress.Web.ASPxWebControl.CallbackError += Application_Error;
}
protected void Application_Error(object sender, EventArgs e) {
Exception exception = System.Web.HttpContext.Current.Server.GetLastError();
if(exception.Message.StartsWith("CallbackException."))
DevExpress.Web.ASPxWebControl.SetCallbackErrorMessage("Upload failed. Please try again later.");
}
I have created a sample project to illustrate this approach.
Best regards,
Pavlo