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

c# – Application_Error未记录错误

发布时间:2020-12-15 08:00:12 所属栏目:百科 来源:网络整理
导读:我有一个Asp.Net 4.0 Web窗体应用程序,在某些时候会抛出以下错误 “Server Error in ‘/MySiteDev’ Application” . 此错误有时会出现.并且此错误未触发在Global.asax中处理的Application_Error事件. 由于这不是触发Application_Error,所有其他可能的地方将
我有一个Asp.Net 4.0 Web窗体应用程序,在某些时候会抛出以下错误

“Server Error in ‘/MySiteDev’ Application” .

此错误有时会出现.并且此错误未触发在Global.asax中处理的Application_Error事件.

由于这不是触发Application_Error,所有其他可能的地方将有这个错误事件的日志?除了事件查看器以外还有什么吗?

有没有办法找出ASP.Net框架处理的异常?

注意:customErrors mode =“Off”.另外runAllManagedModulesForAllRequests =“true”

UPDATE

参考文献How to: Handle Application-Level Errors

An error handler that is defined in the Global.asax file will only catch errors that occur during processing of requests by the ASP.NET runtime. For example,it will catch the error if a user requests an .aspx file that does not occur in your application. However,it does not catch the error if a user requests a nonexistent .htm file. For non-ASP.NET errors,you can create a custom handler in Internet Information Services (IIS). The custom handler will also not be called for server-level errors.

You cannot directly output error information for requests from the Global.asax file; you must transfer control to another page,typically a Web Forms page. When transferring control to another page,use Transfer method. This preserves the current context so that you can get error information from the GetLastError method.

After handling an error,you must clear it by calling the ClearError method of the Server object (HttpServerUtility class).

protected void Application_Error(object sender,EventArgs e)
    {
        //Get the exception object
        Exception exception = Server.GetLastError().GetBaseException();

        //Get the location of the exception
        string location = Request.Url.ToString();
        if (!String.IsNullOrEmpty(location))
        {
            string[] partsOfLocation = location.Split('/');
            if (partsOfLocation != null)
            {
                if (partsOfLocation.Length > 0)
                {
                    location = partsOfLocation[partsOfLocation.Length - 1];
                }
            }

            //Maximum allowed length for location is 255
            if (location.Length > 255)
            {
                location = location.Substring(0,254);
            }
        }

        string connectionString = ConfigurationManager.ConnectionStrings[UIConstants.PayrollSQLConnection].ConnectionString;
        ExceptionBL exceptionBL = new ExceptionBL(connectionString);

        exceptionBL.SubmitException(exception.Message,location);
        Log.Logger.Error(exception.Message);

    }

CONFIG

<system.web>

<compilation debug="true" targetFramework="4.0" />
<pages validateRequest="false"></pages>
<httpRuntime requestValidationMode="2.0" />
<customErrors mode="Off"/>
<authentication mode="Windows"></authentication>
<identity impersonate="true" userName="domainxxxx" password="xxxx"/>

</system.web>

<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<httpErrors errorMode="Detailed" />
</system.webServer>

更新的参考文献

> Application_Error not firing
> Global.asax event Application_Error is not firing
> Application_Error does not fire?
> How to: Handle Application-Level Errors

解决方法

检查事件查看器中的日志,该日志应记录服务器级别和应用程序级别的错误.

应用程序错误处理程序可能不处理事件,因为它是在应用程序成功启动并创建上下文之前发生的.因此,似乎应用程序配置或服务器配置停止处理请求.

或者,应用程序在请求生命周期中尽早遇到问题,即使在启动之后,它也会“挂起”,直到服务器决定终止进程(例如,可能以@MikeSmithDev提到的StackOverflowException的形式).

(编辑:李大同)

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

    推荐文章
      热点阅读