自己asp.net项目错误处理机制
网上看到好项目的错误处理机制,这里列出我的错误处理机制
<customErrors mode="On" defaultRedirect="Error.aspx">
<error statusCode="403" redirect="NoAccess.aspx" /> <!--访问被禁用-->
<error statusCode="404" redirect="Nofound.aspx"/>
<error statusCode="500" redirect="InternalError.aspx"/>
</customErrors>
用log4net记录错误日志和发送电子邮件到开发人员
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' 发生错误时激发
'记录日志发送邮件(略)
End Sub
测试页面:
Imports System.Data Imports System.Data.OleDb Public Class _default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Throw New HttpException(401, "") Throw New HttpException(403, "") 'Throw New HttpException(404, "") 'Throw New HttpException(500, "") End Sub End Class