Reputation: 1677
What is best practice for handling errors that occur in Global.asax (for example in SessionStart)?
In my case I need to handle exceptions that are thrown from a helper class that handles queries against Active Directory.
How do I proceed when I catch an error to inform the user of, for instance, that the AD server cannot be reached?
Upvotes: 0
Views: 1394
Reputation: 13549
If you have a SessionStart method and you're doing work in it, put a try catch in there. If you're talking about errors from your other controllers and other actions, the best way in my opinion is to create a BaseController
and override the OnException
method. Do all your error handling in there (redirect to an error view, log, etc.). Now, when you make a controller, just inherit from BaseController
. See more here:
http://blog.dantup.com/2009/04/aspnet-mvc-handleerror-attribute-custom.html
Upvotes: 1