In ASP.NET MVC im overwriting the OnException, so I can do some custom error handling on exceptions. One thing I would like to do here is to log from what area in the webapplication the error happend.
For example we have Webshop and Administration areas in the webapplications. Then I would like to identify if the exception comes from a Webshop controller or an Administration controller. This is what I have:
protected override void OnException(ExceptionContext filterContext)
{
if (filterContext.Exception != null)
{
ErrorTargetType targetErrorType = ErrorTargetType.DipService;
if (filterContext.Controller is CatalogController)
targetErrorType = ErrorTargetType.WebshopInterface;
LogException(filterContext.Exception, targetErrorType);
}
base.OnException(filterContext);
}
It works fine but I would like do the if statement on a collection of Administration controllers insted. Does ASP.NET MVC have some standard functionality which provides all the controllers in the webapplication in a collection, if so, how do I separate the Webshop controllers from the Administration controllers?
A collection of controllers or controllers group is a notion that doesn’t exist in ASP.NET MVC nor it makes much sense. The fact that you call
ControllerA,ControllerBandControllerCbeing part of Administration is a notion that only you have defined. The sole notion of Administration hardly makes any sense in ASP.NET MVC. In ASP.NET MVC you have Models, Views and of course Controllers.Make them derive from a common base controller or make them implement a marker interface.