views:

98

answers:

2

When the HandleError attribute on a controller detects an unhandled exception and redirects to the Error view, I would like to provide the user with a brief description of the error, and an option to email the error to the application administrator.

I do have a custom HandleError that notifies Elmah to log the error, but having to look up the error in the Elmah log seems a bit of a last resort. Is there any other way to access the unhandled exception that is 'caught' by HandleError?

+3  A: 

HandleErrorAttribute supplies a Model object of type HandleErrorInfo Your Error page could look like this

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<HandleErrorInfo>" %>

The Model has an Exception property with the details of the exception handled.

I usually use a custom error handler that also logs the exception using log4net and I have an STMP appender that emails me whenever an exception is handled by the filter.

uvita
A: 

how do you bind this from controller?

i'm using the ErrorLog_Logged event handler in global asax but i can't pass the error to controller.

can you provide me a sample?

Marco