I have an ASP.NET MVC website that connects to a DB via a Web Service.
If the WebService is not contactable, I want to redirect the user to a page explaining the service isn’t running. Currently it just crashes when the WebService doesnt respond properly.
What is the best method to achieve this? I have lots of controllers so writing error trapping code for each function in each controller for this specific case would be tedious and involve a lot of code repeation.
One easy option is to write a base-controller; override the methods you want (whether that is before the call (
OnActionExecuting) or upon exception (OnException)), and just add: MyBaseControllerto each controller.Another option would be to decorate each controller with a filter-attribute that does the same work.