views:

317

answers:

1

Simple question: If I've got a generic Error.aspx page in my Shared folder (and the requisite HandleError on my controller). How do I show the exception message that triggered it?

This Scott Gu post states that the functionality should be in the default Error.aspx generated with new projects, but that was Preview 4, and I'm assuming that fell out with the v1.0 release.

+2  A: 

ASP.NET MVC HandleError Attribute, Custom Error Pages and Logging Exceptions

ASP.NET has a nice web.config setting that configures custom errors. This property is exposed via MVC, so we can set up our config to show friendly errors to remote users only:

<customErrors mode="RemoteOnly" />
Robert Harvey
Good article. To complete the loop, I'm overriding OnException and adding the exception message to a TempData variable so I can show it on the Error.aspx page. Thanks.
gfrizzle
You should never ... and I stress never ... under any circumstance reveal the details of an exception to your users. Also, you'll need to use the [HandleError] action filter on your controller(s) or class(s) as well.http://msdn.microsoft.com/en-us/library/dd410203.aspx
Nissan Fan