ASP.NET未处理异常(Unhandled Exception)调试试验

本文探讨了ASP.NET中未处理异常导致的两种不同结果,即进程退出和显示错误页面。通过windbg调试,揭示了异常处理机制,并提供了调试未处理异常的方法,包括记录异常调用栈和捕获崩溃转储。解决方案涉及调整配置或使用日志记录异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题介绍

网站运行的时候是否遇到过未处理异常(unhandled exception)造成网站进程退出报503(service unavailable)错误?但是也有时未处理异常仅仅是在页面上显示出错信息,网站进程还在照常运行。

  • 为什么同样发生了异常,结果却截然不同?
  • 这种问题该如何调试?

这片文章通过调试试验来揭开这些问题的答案。


第一种情况

ASP.NET网站运行过程中莫名其妙的退出,在系统事件日志中会有如下记录。

Log Name:      System
Source:        Microsoft-Windows-WAS
Date:          10/6/2012 5:20:03 PM
Event ID:      5011
Task Category: None
Level:         Warning
Keywords:      Classic
User:          N/A
Computer:      system-02
Description:
A process serving application pool 'xxx' suffered a fatal communication error with the Windows Process Activation Service. The process id was '5284'. The data field contains the error number.
应用程序日志中有ASP.NET的 错误消息
An unhandled exception occurred and the process was terminated.

Application ID: /LM/W3SVC/2/ROOT

Process ID: 3016

Exception: System.Exception

Message: Exception of type 'System.Exception' was thrown.

StackTrace:    at ASP.backgroundexception_aspx.CrashSite(Object arg)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
如果这种错误很短时间内出现次数过多的话,接下来网站就不能访问了,直接返回这样的页面。(这是因为IIS默认提供出错保护,默认情况下在5分钟内出错5次就会自动停掉程序池)


系统日志中也会有这么一条记录。

Log Name:      System
Source:        Microsoft-Windows-WAS
Date:          10/6/2012 6:50:53 PM
Event ID:      5002
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      system-02
Description:
Application pool 'xxx' is being automatically disabled due to a series of failures in the process(es) serving that application pool.


第二种情况

网站同样报出异常,服务器返回错误页面。


应用程序日志中记录为一个警告,当时系统日志中并没有相应的错误。w3wp进程也没有退出。

Log Name:      Application
Source:        ASP.NET 2.0.50727.0
Date:          10/6/2012 5:54:53 PM
Event ID:      1309
Task Category: Web Event
Level:         Warning
Keywords:      Classic
User:          N/A
Computer:      system-02
Description:
Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 10/6/2012 5:54:53 PM 
Event time (UTC): 10/6/2012 9:54:53 AM 
Event ID: 55545893cefc429d895523e8aadc3e01 
Event sequence: 12 
Event occurrence: 3 
Event detail code: 0 
 
Application information: 
    Application domain: /LM/W3SVC/2/ROOT-1-129939906465074620 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: C:\inetpub\webdebug\ 
    Machine name: DOFWIN8-02 
 
Process information: 
    Process ID: 3016 
    Process name: w3wp.exe 
    Account name: NT AUTHORITY\LOCAL SERVICE 
 
Exception information: 
    Exception type: Exception 
    Exception message: Exception of type 'System.Exception' was thrown. 
 
Request information: 
    Request URL: http://localhost:8080/ForegroundException.aspx 
    Request path: /ForegroundException.aspx 
    User host address: ::1 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: NT AUTHORITY\LOCAL SERVICE 
 
Thread information: 
    Thread ID: 6 
    Thread account name: NT AUTHORITY\LOCAL SERVICE 
    Is impersonating: False 
    Stack trace:    at ASP.foregroundexception_aspx.Page_Load(Object sender, EventArgs e) 
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 

调试试验

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值