登錄我拋出以下錯誤某些時候錯誤不與的Application_Error
「服務器錯誤/ MySiteDev「應用程序」的
Asp.Net 4.0 Web Forms
應用。
此錯誤只在有時。並且此錯誤不會觸發在Global.asax
中處理的Application_Error
事件。
由於這不是觸發Application_Error,所有其他可能的地方會有這個錯誤事件的日誌?除事件查看器以外的任何其他可用內容
有沒有辦法找出ASP.Net框架處理的異常?
注意:customErrors mode="Off"
。此外runAllManagedModulesForAllRequests="true"
UPDATE
借鑑How to: Handle Application-Level Errors
是在Global.asax文件中定義將只捕獲由ASP.NET運行時請求的處理過程中發生的錯誤的錯誤處理程序。例如,如果用戶請求在應用程序中不存在的.aspx文件,它將捕獲錯誤。但是,如果用戶請求不存在的.htm文件,則不會捕獲該錯誤。對於非ASP.NET錯誤,您可以在Internet Information Services(IIS)中創建自定義處理程序。自定義處理程序也不會被調用服務器級錯誤。
您無法直接輸出Global.asax文件請求的錯誤信息;您必須將控制權轉移到其他頁面,通常是Web窗體頁面。將控制權轉移到其他頁面時,請使用轉移方式。這保留了當前上下文,以便您可以從GetLastError方法中獲取錯誤信息。
處理完一個錯誤後,您必須通過調用服務器對象的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>
修訂參考
- Application_Error not firing
- Global.asax event Application_Error is not firing
- Application_Error does not fire?
- How to: Handle Application-Level Errors
擊敗我吧!此外,可能是StackOverflowException ...我有興趣從事件日誌中查看OP詳細信息。 – MikeSmithDev 2013-02-14 14:20:12
@MikeSmithDev下面的文章說:「它是一個」stackoverflow「異常或」404未找到「它將最終在Application_Error。」你是說這個說法不正確? StackOverflow異常將不會被Application_Error捕獲? http://totaldotnet.com/Article/ShowArticle58_GlobleErrorHandle.aspx – Lijo 2013-02-14 15:11:56
@Lijo是的,這就是我說的。我只是測試你的代碼。它抓到了一個例外。當我發生StackOverflowException時,它沒有捕獲它。 Try/Catch也無法捕捉到它們。相應的過程立即終止。如果這種情況發生得太多,通常情況下,app_pool將被關閉,您的網站將基本上死機,直到您回收它。 – MikeSmithDev 2013-02-14 15:55:25