【发布时间】:2026-02-08 14:25:01
【问题描述】:
我有一个 .NET 4.0 Web 应用程序,它在 Global.asax 的 Application_Error 事件中实现了一个错误处理程序。
当发生异常时,它会拦截它并向我发送一封电子邮件,其中包含各种信息,例如登录用户、发生错误的页面、会话内容等。
这一切都很好,但是缺少一些我似乎无法找到的基本细节。
例如,这是我将收到的错误和相关堆栈跟踪的子集:
Source: Telerik.Web.UI
Message: Selection out of range
Parameter name: value
Stack trace: at Telerik.Web.UI.RadComboBox.PerformDataBinding(IEnumerable dataSource)
at Telerik.Web.UI.RadComboBox.OnDataSourceViewSelectCallback(IEnumerable data)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e)
at Telerik.Web.UI.RadComboBox.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at Telerik.Web.UI.RadComboBox.DataBind()
at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
at Telerik.Web.UI.RadComboBox.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
现在很可爱,我可以知道 a) 控件的名称和 b) 导致控件“超出范围”的值。
关于如何获取此类信息的任何建议?我已经在调试模式下运行了它,传递给 Global.asax 的对象似乎没有我能看到的更多细节。
【问题讨论】:
-
你需要
catch它发生的异常并从那里记录它以获得你正在寻找的信息。 -
您是否尝试过覆盖
MasterPage.OnError(EventArge)? -
您如何获得已经显示的数据?是否异常不包含您想要的信息?如果是这样,除非您能够向抛出的异常添加更多数据,否则您可能会不走运......
-
感谢 Brian,但是对于一个包含 1000 个控件的应用程序,为每个控件设置单独的处理程序有点不切实际
-
@cusimar9:你有母版页吗?试着处理进去。
标签: asp.net .net exception exception-handling global-asax