J4N
J4N

Reputation: 20707

Globally manage unexpected exception in asp.net MVC

I'm coming at the end of the development of my application.

Everything is working fine, but if once somebody got an unexpected exception, I would like to be able to:

  1. Redirect him to a user-friendly page explaining that we got a problem.(Specifying a controller/action)
  2. Log every information of the stack trace, current controller/action, parameter, session data, ...

What is the best way to do it with asp.net MVC?

EDIT

In complement of the great answer: I integrated elmah like described here: http://joel.net/logging-errors-with-elmah-in-asp.net-mvc-3--part-1--setup And then I specified some custom error page. So now I've all I need!

Upvotes: 0

Views: 456

Answers (4)

Tomi Lammi
Tomi Lammi

Reputation: 2126

Take a look at PostSharp, neat and easy to use. Starter version available to use after free registration. NuGet package also available http://nuget.org/packages/PostSharp

Upvotes: 0

Simon Linder
Simon Linder

Reputation: 3428

You can catch errors in the global.asax. There is a method protected void Application_Error(object sender, EventArgs e) where you can do what ever you want.

Upvotes: 1

JcMaltaDev
JcMaltaDev

Reputation: 1364

I would recommend you use "Elmah" http://code.google.com/p/elmah/

This package is a godsend - does exactly what is shown on the box, with close to ZERO changes to your source code.

It is also available via NuGet at http://nuget.org/packages/elmah

Upvotes: 2

Related Questions