c# – 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="domain\xxxx" 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的形式).

相关文章

在项目中使用SharpZipLib压缩文件夹的时候,遇到如果目录较深,则压缩包中的文件夹同样比较深的问题。比...
项目需要,几十万张照片需要计算出每个照片的特征值(调用C++编写的DLL)。 业务流程:选择照片...
var array = new byte[4]; var i = Encoding.UTF8.GetBytes(100.ToString(&quot;x2&quot;));//...
其实很简单,因为Combox的Item是一个K/V的object,那么就可以把它的items转换成IEnumerable&lt;Dic...
把.net4.6安装包打包进安装程序。 关键脚本如下: 头部引用字符串对比库 !include &quot;WordFunc....
项目需求(Winform)可以批量打印某个模板,经过百度和摸索,使用iTextSharp+ZXing.NetʿreeSp...