胖在一方

出得厅堂入得厨房的胖子

导航

WebForm自定义错误页面

Posted on 2006-09-12 17:14  胖在一方  阅读(832)  评论(1)    收藏  举报

 

 1 1. 在global.asax 中,处理 Application_error事件 
 2 Sub Application_Error(ByVal sender As ObjectByVal e As
 EventArgs)
 3         ' 在发生错误时激发

 4         Server.Transfer(Request.ApplicationPath & "/ErrMessage.aspx")
 5 
End Sub

 6 2. ErrMessage.aspx代码
 7 '在此处放置初始化页的用户代码

 8 Dim domException As Exception = Server.GetLastError.InnerException.GetBaseException
 9 Me.lblExceptionURL.Text =
 Request.Url.ToString
10 Me.lblExceptionMethodName.Text = domException.TargetSite.Name  '错误的方法名

11 Me.lblExceptionMessage.Text = domException.Message.Replace(ControlChars.Lf, "<br>")      '错误的信息
12 Me.lblExceptionTrackMessage.Text = domException.StackTrace.Replace(ControlChars.CrLf, "<br>"'堆栈上的信息
13 

效果: