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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET Core 基础教程-约定 - ASP.NET Core 基础教程 - 简
- asp.net-mvc – 编译错误“无法在Web部署项目中加载类型’S
- asp.net-mvc – EntityType’ApplyantPosition’没有定义键
- asp.net – 使用IHttpControllerSelector的AttributeRoutin
- Visual Studio 2017下ASP.NET CORE的TagHelper智能提示解决
- asp.net – Visual Studio 2013更改现有项目的身份验证
- 在ASP.Net中加载用户控件并处理回发
- asp.net-mvc – 在链接文本中使用HTML元素创建一个ActionLi
- asp.net-mvc – 如何在MVC Filter属性中解析依赖注入
- asp.net-mvc – 如何从HttpContext获取JWT(使用OpenIdConne
推荐文章
站长推荐
热点阅读