您的位置:首页 > 编程语言 > ASP

ASP.Net异常的捕获小结

2010-10-18 16:19 387 查看
四种方法:

建立一个PageBase (class),自定义OnError事件
在Global.asax中自定义Application_Error事件
在web.config中定义新的页面
<customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx"/>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

自定义GeneralError.aspx捕获异常
在HttpModule中自定义OnError事件

例子:

Offending URL: " + ctx.Request.Url.ToString () +
"
Source: " + exception.Source +
"
Message: " + exception.Message +
"
Stack trace: " + exception.StackTrace;

ctx.Response.Write (errorInfo);

// --------------------------------------------------
// To let the page finish running we clear the error
// --------------------------------------------------
ctx.Server.ClearError ();

base.OnError (e);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: