Hi All
In the application I developed, I had the code to log the exceptions in Global.asax. This was working fine until I use Ajax update panel in the code behind of a few files.
When an exception happens in the code, called through update panel, Application_Error handler in the global.asax is never called.
Instead I can see an alert with the exception.message.
Is this a known issue? if so, is there a was to call the Application_Error automatically in case any exception thrown.
Thanks
Hi,
It's not a issue, but designed to work so.
If it's a asyncRequest, an custom error handler will be registered to handle any exception. The error message is encoded and returned in the internal error handler. And it's worth mentioning that this exception isn't swallowed and theoretically speaking, the appliction_error is able to fire.
Hi,
Thanks for the reply.
But the Application_Error event is not called.
I tried setting breakpoint in the function entry point and indused an Object Reference Is Nothing Errror within the code that is called through UpdatePanel. The breakpoint is not getting hit. Even in the test server, the errors are not getting logged. Is there any way, we can override the Ajax custom error handler or just make the Application_Error event to be called.
I used the following code, and it's able to trigger the Application_Error method.
<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); throw new Exception("custom exception"); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>
Can you try it? Please let me know the result.
Hi
One more thanks for the reply.
I tried the code, the exception is getting thrown, but still the breakpoint in application_error is not being hit.
Can you simplify your app into a single page along with web.config that is able to reproduce the problem and mail it to me?
Hi Mr.Raymond Wen,
Many thanks for your continued support.
Below I post a simple "Not in use" page, for your understanding
<%@. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> </script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Partial-Page Update Error Handling Example</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox> / <asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox> = <asp:Label ID="Label1" runat="server"></asp:Label><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" /> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>
PartialClass _DefaultInherits System.Web.UI.PageProtected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Try Throw New Exception("FOR TESTING")Finally End Try End SubEnd Class
GLOBAL.ASAX
'This code is not being called during an asyncronous postback'But this is called when a request is made directly without using UpdatePanel.Sub Application_Error(ByVal senderAs Object,ByVal eAs EventArgs)Dim exAs System.Exception = Server.GetLastError()TryIf ex IsNotNothing ThenWriteLog(ex)End IfServer.Transfer("~/ErrorDescriptionPage.aspx")CatchEnd TryEnd SubHope this will help to identify the issue.
Thanks once again
One more thing is that I use Microsoft Entreprise Block for exception handling
Thanks
Still, I can fire the Application_Error method. I guess it's caused by come configurations. That's why I want your web.config file.
Can you post it here?
No comments:
Post a Comment