I have user errors included in my web.config file:

Error handling in UpdatePanel with <CustomErrors mode = "On" / ">

I have user errors included in my web.config file:

<customErrors mode="On" defaultRedirect="~/ErrorPage.aspx" /> 

When an error occurs during an asynchronous postback in UpdatePanel, the response is returned as code 200, and the content as an error page.

This breaks when UpdatePanel tries to parse the response and throws a JavaScript exception:

Sys.WebForms.PageRequestManagerParserErrorException: A message received from the server cannot be parsed.

Is there a way to handle this correctly on the client side without having to disable the custom error, since I don't want to disclose any details of the exception?

+6
source share
1 answer

One way to handle this is to connect the OnAsyncPostBackError event to the ScriptManager :

 <asp:ScriptManager ID="ScriptManager1" runat="server" AllowCustomErrorsRedirect="False" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError" /> 

This MSDN page contains a complete example of using this method to handle asynchronous backward errors.

EDIT
To work around the problem with custom error pages, be sure to set the AllowCustomErrorsRedirect property to ScriptManager to false . As soon as I set this property to false, I was able to get the MSDN sample to work correctly, even if I had the CustomErrors mode = "On" mode set in the web.config file.

+4
source

Source: https://habr.com/ru/post/887678/


All Articles