获取自定义页面上的所有默认错误信息

时间:2016-06-27 18:30:39

标签: c# asp.net error-handling

我如何能够将默认错误页面中的所有信息捕获到自定义错误页面上。我目前能够获得堆栈跟踪但我真的想要描述和异常细节。

我目前通过执行以下操作获取堆栈跟踪

HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError();
exception.StackTrace.ToString()

但我真的想得到异常细节。 (以下是我收到的默认页面)

Server Error in '/' Application.

The TargetControlID of 'mp1' is not valid. A control with ID 'btnShow' could not be found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The TargetControlID of 'mp1' is not valid. A control with ID 'btnShow' could not be found.

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 
[InvalidOperationException: The TargetControlID of 'mp1' is not valid. A control with ID 'btnShow' could not be found.]
   System.Web.UI.ExtenderControl.RegisterWithScriptManager() +356
   System.Web.UI.ExtenderControl.OnPreRender(EventArgs e) +20
   AjaxControlToolkit.ExtenderControlBase.OnPreRender(EventArgs e) +64
   AjaxControlToolkit.ModalPopupExtender.OnPreRender(EventArgs e) +188
   System.Web.UI.Control.PreRenderRecursiveInternal() +88
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +883

0 个答案:

没有答案