Creating an Attribute to check for Exceptions
Posted
by
BiffBaffBoff
on Stack Overflow
See other posts from Stack Overflow
or by BiffBaffBoff
Published on 2012-04-13T11:11:20Z
Indexed on
2012/04/13
11:29 UTC
Read the original article
Hit count: 209
c#
|asp.net-mvc-3
I'm creating an attribute so that whenever an exception occurs on my site, I'll receive an email detailing the exception. I've got so far but my Attribute code doesn't seem to fire if an exception occurs:
public class ReportingAttribute : FilterAttribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
// This will generate an email to me
ErrorReporting.GenerateEmail(filterContext.Exception);
}
}
Then above my Controller I'm doing:
[ReportingAttribute]
public class AccountController : Controller
The other way to do it is ofcourse putting ErrorReporting.GenerateEmail(ex)
inside my catch blocks? There must be a simpler way? Thats why I thought of creating the Attribute to handle this
© Stack Overflow or respective owner