开发者

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

开发者 https://www.devze.com 2023-03-04 08:15 出处:网络
I have custom errors enabled in my web.config file: <customErrors mode=\"On\" defaultRedirect=\"~/ErrorPage.aspx\" />

I have custom errors enabled in my web.config file:

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

When an error happens during an asynchronous postback in an UpdatePanel, the response comes back as a code 200 and the content set as the error page.

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

Sys.WebForms.PageRequestManagerParserErro开发者_如何学JAVArException: message received from the server could not be parsed.

Is there a way to properly handle this on the client side without having to disable the custom error, as I do not want to divulge any exception details?


One way to handle this would be to wire up the OnAsyncPostBackError event on your ScriptManager control:

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

This page on MSDN has a full example using this method to handle async postback errors.

EDIT
To get around the issue with the custom error pages be sure to set the AllowCustomErrorsRedirect property on the ScriptManager to false. Once I set this property to false I was able to get the MSDN sample to work properly even though I had CustomErrors mode="On" set in the web.config.

0

精彩评论

暂无评论...
验证码 换一张
取 消