eb_ncsnb2-n, P5 0.0.0.0, P6 440a4082, P7 5, P8 1, P9 system.nullreferenceexception, P10 NIL. 要截获 ASP.
NET 的未捕获异常,我们需要为每个应用程序域安装事件钩子 这个过程需要分两步完成: 首先创建一个实现 IHttpModule 接口的类
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
namespace WebMonitor { ///
/// Summary description for UnhandledExceptionModule /// public class UnhandledExceptionModule : IHttpModule { static object _initLock = new object(); static bool _initialized = false;
public UnhandledExceptionModule() { // // TODO: Add constructor logic here
// }
void OnUnhandledException(object o, UnhandledExceptionEvent Args e) { //Do some thing you wish to do when the Unhandled Excep tion raised.
try {
using (System.IO.FileStream fs = new System.IO.File Stream(@"c:\testme.log", System.IO.FileMode.Append, System.IO.FileAcc ess.Write)) { usi
ng (System.IO.StreamWriter w = new System.IO. StreamWriter(fs, System. Text.Encoding.UTF8)) { w.WriteLine(e.ExceptionObject); } } } catch { } } IHttpModule Members } }
第二步:
修改
web.config 在 system.web 段中加入
完成这两步后,你的 ASP.NET 应用就可以截获未捕获异常了。 下面是测试代码
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page { protected void Pa