internal List <RouteEntry> MapMvcAttributeRoutes(ReflectedAsyncControllerDescriptor controllerDescriptor) { RoutePrefixAttribute prefixAttribute = GetPrefixFrom(controllerDescriptor); ValidatePrefixTemplate(prefixAttribute, controllerDescriptor); RouteAreaAttribute area = GetAreaFrom(controllerDescriptor); string areaName = GetAreaName(controllerDescriptor, area); string areaPrefix = area != null ? area.AreaPrefix ?? area.AreaName : null; ValidateAreaPrefixTemplate(areaPrefix, areaName, controllerDescriptor); string controllerName = controllerDescriptor.ControllerName; AsyncActionMethodSelector actionSelector = controllerDescriptor.Selector; IEnumerable <MethodInfo> actionMethodsInfo = actionSelector.AliasedMethods .Concat(actionSelector.NonAliasedMethods.SelectMany(x => x)) .Where(m => m.DeclaringType == controllerDescriptor.ControllerType); if (actionSelector.AllowLegacyAsyncActions) { // if the ActionAsync / ActionCompleted pattern is used, we need to remove the "Completed" methods // and not look up routing attributes on them actionMethodsInfo = actionMethodsInfo.Where(m => !m.Name.EndsWith("Completed", StringComparison.OrdinalIgnoreCase)); } List <RouteEntry> routeEntries = new List <RouteEntry>(); foreach (var method in actionMethodsInfo) { string actionName = GetCanonicalActionName(method, actionSelector.AllowLegacyAsyncActions); IEnumerable <IDirectRouteInfoProvider> routeAttributes = GetRouteAttributes(method); foreach (var routeAttribute in routeAttributes) { ValidateTemplate(routeAttribute, actionName, controllerDescriptor); string prefix = prefixAttribute != null ? prefixAttribute.Prefix : null; string template = CombinePrefixAndAreaWithTemplate(areaPrefix, prefix, routeAttribute.RouteTemplate); Route route = _routeBuilder.BuildDirectRoute(template, routeAttribute.Verbs, controllerName, actionName, method, areaName); RouteEntry entry = new RouteEntry { Name = routeAttribute.RouteName ?? template, Route = route, RouteTemplate = template, ParsedRoute = RouteParser.Parse(route.Url), Order = routeAttribute.RouteOrder }; routeEntries.Add(entry); } } return(routeEntries); }
internal List <RouteEntry> MapMvcAttributeRoutes(ReflectedAsyncControllerDescriptor controllerDescriptor) { string prefix = controllerDescriptor.GetPrefixFrom(); ValidatePrefixTemplate(prefix, controllerDescriptor); RouteAreaAttribute area = controllerDescriptor.GetAreaFrom(); string areaName = controllerDescriptor.GetAreaName(area); string areaPrefix = area != null ? area.AreaPrefix ?? area.AreaName : null; ValidateAreaPrefixTemplate(areaPrefix, areaName, controllerDescriptor); string controllerName = controllerDescriptor.ControllerName; AsyncActionMethodSelector actionSelector = controllerDescriptor.Selector; IEnumerable <MethodInfo> actionMethodsInfo = actionSelector.DirectRouteMethods; List <RouteEntry> routeEntries = new List <RouteEntry>(); foreach (var method in actionMethodsInfo) { string actionName = actionSelector.GetActionName(method); IEnumerable <IRouteInfoProvider> routeAttributes = GetRouteAttributes(method, controllerDescriptor.ControllerType); IEnumerable <string> verbs = GetActionVerbs(method); foreach (var routeAttribute in routeAttributes) { ValidateTemplate(routeAttribute.Template, actionName, controllerDescriptor); string template = CombinePrefixAndAreaWithTemplate(areaPrefix, prefix, routeAttribute.Template); Route route = _routeBuilder.BuildDirectRoute(template, verbs, controllerName, actionName, method, areaName); RouteEntry entry = new RouteEntry { Name = routeAttribute.Name, Route = route, Template = template, ParsedRoute = RouteParser.Parse(route.Url), HasVerbs = verbs.Any() }; routeEntries.Add(entry); } } // Check for controller-level routes. IEnumerable <IRouteInfoProvider> controllerRouteAttributes = controllerDescriptor.GetDirectRoutes(); foreach (var routeAttribute in controllerRouteAttributes) { string template = CombinePrefixAndAreaWithTemplate(areaPrefix, prefix, routeAttribute.Template); Route route = _routeBuilder.BuildDirectRoute(template, controllerDescriptor); RouteEntry entry = new RouteEntry { Name = routeAttribute.Name, Route = route, Template = template, ParsedRoute = RouteParser.Parse(route.Url) }; routeEntries.Add(entry); } return(routeEntries); }