加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何忽略全局asax中图像的日志记录错误

发布时间:2020-12-16 07:17:05 所属栏目:asp.Net 来源:网络整理
导读:我的global.asax中有一个错误处理程序,如下所示; Sub Application_Error(ByVal sender As Object,ByVal e As EventArgs) ' Code that runs when an unhandled error occurs Dim ex = Server.GetLastError.GetBaseException Dim lastErrorWrapper As HttpExce
我的global.asax中有一个错误处理程序,如下所示;

Sub Application_Error(ByVal sender As Object,ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs
        Dim ex = Server.GetLastError.GetBaseException
        Dim lastErrorWrapper As HttpException = Server.GetLastError()
        Dim lastError As Exception = lastErrorWrapper

        If lastErrorWrapper.InnerException IsNot Nothing Then
            lastError = lastErrorWrapper.InnerException
        End If

        My.ErrorHandler.LogError( _
            "<BR/><BR/>URL: " & Request.RawUrl & _
            "<BR/><BR/>STACK: " & ex.StackTrace & _
            "<BR/><BR/>SOURCE: " & ex.Source & _
            "<BR/><BR/>MESSAGE: " & ex.Message & _
            "<BR/><BR/>TYPENAME: " & ex.GetType.ToString & _
            "<BR/><BR/>INNER EXCEPTION: " & lastError.ToString & _
            "<BR/><BR/>REFERRER: " & HttpContext.Current.Request.Url.AbsoluteUri & _
            "<BR/><BR/>USER IP: " & Request.ServerVariables("REMOTE_ADDR") & " -- " & Request.ServerVariables("HTTP_USER_AGENT"))
    End Sub

显然,这很有效,并在发生错误时向我发送电子邮件.但是,对于文件系统中找不到的任何图像也是如此.它给了我一个“文件不存在”.错误.有没有办法忽略不在磁盘上的图像的日志记录错误?

解决方法

你不能解决FileNotFoundException吗?如果不应该发生异常,则解决问题而不是解决问题.要处理已知异常,您可以使用以下代码.

if(Server.GetLastError().GetBaseException() is System.Web.HttpException)
{
     //You could check whether the 
     //Server.GetLastError().GetBaseException().Message contains the appropriate message
     Debug.WriteLine("Suppressed FileNotFoundException");
}else
//Log an unhandled exception

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读