私のサイトで例外が発生するたびに例外を詳述する電子メールが送られるように属性を作成しています。私はこれまで持っているが、例外が発生した場合、私の属性コードが発射していないようです: 例外を確認するための属性の作成
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
それを行うための他の方法を私のキャッチブロックにErrorReporting.GenerateEmail(ex)
を入れているのはどうですか?より簡単な方法が必要ですか?ただ、それ自体でできないを
private void Application_Error(object sender, EventArgs e)
{
try
{
//
// Try to be as "defensive" as possible, to ensure gathering of max. amount of info.
//
HttpApplication app = (HttpApplication) sender;
if(null != app.Context)
{
HttpContext context = app.Context;
if(null != context.AllErrors)
{
foreach(Exception ex in context.AllErrors)
{
// Log the **ex** or send it via mail.
}
}
context.ClearError();
context.Server.Transfer("~/YourErrorPage");
}
}
catch
{
HttpContext.Current.Response.StatusCode = (int) HttpStatusCode.InternalServerError;
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
からあなたのコントローラを引き出すには、 'IExceptionFilter.OnException()'だけで未処理の例外で呼び出されていないですか? –