85280

How do I access an unhandled exception in an MVC Error view?

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?

Answer1:

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.

Recommend

  • Using a parameterless controller constructor with Ninject?
  • accessing/handling wireless keboard input(key press) in my ipad application
  • ASP.NET MVC Global Error Handling with ELMAH - best practices
  • accessing/handling wireless keboard input(key press) in my ipad application
  • How to retain file input value after form submission with errors?
  • Design suggestions for client receiving messages over network
  • Threading in Java
  • How to use custom Exception in Session Beans?
  • jQuery .on() not bound when script inserted into the DOM
  • How to create and attach to email multiple PDFs using iTextSharp?
  • Elmah.MVC does not log errors in production environment
  • Unable to catch exception from TimerTask thread
  • Qt — pass events to multiple objects?
  • Detect when user takes a screen shot in windows with print screen?
  • Thrift: Is it possible to do only serialization with the C (GLib) Thrift library?
  • How to notify a specific thread in Java
  • Visual studio alerts workspace already exists
  • Netezza Incremental load from Sql server using SSIS
  • What is this iOS exception with NSCFType?
  • HttpListener.IsSupported is false on XP SP3
  • import scipy.sparse failed
  • Login not working in Firefox in Meteor
  • How to define custom class, title, and target in Link Browser for content elements and the new rte_c
  • How do I access an unhandled exception in an MVC Error view?
  • Email verification using google app script and google forms
  • Google Custom Search with transparent background
  • NHibernate Validation Localization with S#arp Architecture
  • Email format validation in mvc3 view
  • C# - Serializing and deserializing static member
  • Bug in WPF DataGrid
  • Sending data from AppleScript to FileMaker records
  • sending/ receiving email in Java
  • vba code to select only visible cells in specific column except heading
  • Redux, normalised entities and lodash merge
  • How to include full .NET prerequisite for Wix Burn installer
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Benchmarking RAM performance - UWP and C#
  • how does django model after text[] in postgresql [duplicate]
  • Is it possible to post an object from jquery to bottle.py?
  • To Get the radio button value in ruby on rails