0

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?

2
  • What kind of errors? For what event handler? Commented May 25, 2011 at 12:05
  • I improved the question a bit. Commented May 25, 2011 at 12:13

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah but if I catch some exception in the SessionStart method, how do I proceed from there? Can I redirect to my error controller?
No, that's outside of a request, so you don't have anything to redirect - SessionStart is before any action is invoked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.