我創建了一個屬性,以便每當我的網站發生異常時,我都會收到一封詳細說明該異常的電子郵件。我有這麼遠,但我的屬性代碼似乎不火,如果發生異常:創建屬性以檢查異常
public class ReportingAttribute : FilterAttribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
// This will generate an email to me
ErrorReporting.GenerateEmail(filterContext.Exception);
}
}
然後我上面的控制器我做:
[ReportingAttribute]
public class AccountController : Controller
的另一種方式做到這一點我的catch塊裏面有ErrorReporting.GenerateEmail(ex)
嗎?必須有一個更簡單的方法?這就是爲什麼我認爲創建屬性來處理這個
派生控制器不'IExceptionFilter.OnException()'只調用上未處理的異常? – 2012-04-13 11:30:50