我有一个Asp.Net 4.0 Web Forms
应用程序会在某些时候抛出错误
“'/ MySiteDev'应用程序中的服务器错误”。
此错误有时会出现。此错误未触发Application_Error
中处理的Global.asax
事件。
由于这不会触发Application_Error,所有其他可能的地方都会记录此错误事件?除了事件查看器以外还有什么吗?
找出ASP.Net框架处理的异常的任何方法?
注意:customErrors mode="Off"
。另外runAllManagedModulesForAllRequests="true"
更新
来自How to: Handle Application-Level Errors
的参考资料Global.asax文件中定义的错误处理程序仅捕获ASP.NET运行时处理请求期间发生的错误。例如,如果用户请求您的应用程序中没有出现的.aspx文件,它将捕获错误。但是,如果用户请求不存在的.htm文件,它不会捕获错误。对于nonASP.NET错误,您可以在Internet信息服务(IIS)中创建自定义处理程序。也不会为服务器级错误调用自定义处理程序。
您无法直接输出Global.asax文件请求的错误信息;您必须将控制权转移到另一个页面,通常是Web窗体页面。将控件转移到另一页时,请使用Transfer方法。这将保留当前上下文,以便您可以从GetLastError方法获取错误信息。
处理完错误后,必须通过调用Server对象的ClearError方法(HttpServerUtility类)清除它。
CODE
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>
更新的参考资料
答案 0 :(得分:3)
检查事件查看器中的日志,该日志应记录服务器级别和应用程序级别的错误。
应用程序错误处理程序可能不处理事件,因为它是在应用程序成功启动并创建上下文之前发生的。因此,似乎有一个应用程序配置或服务器配置停止处理请求。
或者,应用程序在请求生命周期中遇到问题,即使在启动之后,它也会“挂起”,直到服务器决定终止该进程(例如,可能以@MikeSmithDev提到的StackOverflowException的形式)
答案 1 :(得分:1)
这是一个带有A和B框的load balanced
环境。
部署Web应用程序的团队确认,在其中一个框中,配置文件未正确复制。
我认为,该应用程序在点击A框并且在B框中失败时运行良好。我认为,由于配置不存在,因此无法调用Application_Error
。
请告诉您是否有不同意见。
注意:重新部署时问题不存在