I have a asp.net mvc 3 application with IIS7 and IIS express on local, which is using Application_Error for logging the exceptions and redirecting to a custom error page. My application has different regions, and the application_error is called whenever the controller or the action is not matched, but not for the region.
Here is an example of the routes used:
routes.MapRoute(
"Default",
"{region}/{controller}/{action}/{id}",
new { region = "uk", controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new { region = new RegionWhitelistConstraint() } // constraint for valid regions
);
In this case the Application_Error would be fired for /uk/NotFoundPage but not for /foo/Home
Here the constraint for the region:
public class RegionWhitelistConstraint : IRouteConstraint
{
public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
var whiteList = Region.DefaultWhiteList;
var currentRegionValue = values[parameterName].ToString();
return whiteList.Contains(currentRegionValue);
}
}
I have seen this question, that propose adding a catch all route, but apart from that I would like to know if there is a way of firing Application_Error as it is done for the controllers or actions.