In this scenario I wish too bypass my normal error logging, which wont work, and simply request the Error view and and send an email. I don’t wish to duplicate this special case handling in all controllers, and DB access might be attempted before any action is requested. Where should I place this special handler, and if not in a controller, how do I call up the Error view?
Oh yes, I’m using Elmah for routine logging of unhandled exceptions.
Try using something along these lines in your controller
Now in your
Views/Shared/folder you can create a View called “SqlError.aspx” that will be returned if there’s a SQL Exception.I would also recommend handling all of your Application Error “stuff” in the Global.asax file. IE: the part that does the emailing of the error, logging of the error, etc.
Check out this SO question for an idea
ASP.NET MVC Custom Error Handling Application_Error Global.asax?