示例#1
0
        internal List <Route> GetMatchedRoutes(string path)
        {
            PortalTrace.Write("Routes", "GetMatchedRoutes", "Begin GetMatchedRoutes.");

            List <Route> matchedRoutes = new List <Route>();

            foreach (KeyValuePair <string, Route> route in primaryRoutes)
            {
                if (!route.Value.IsMatch(path))
                {
                    continue;
                }

                PortalTrace.Write("Routes", "GetMatchedRoutes", "Found matching primary route '{0}'", route.Value.RouteName);
                matchedRoutes.Add(route.Value);
                break;
            }

            if (matchedRoutes.Count == 0)
            {
                PortalTrace.Warn("Routes", "GetMatchedRoutes", "No matching primary routes found.");
                if (!defaultRoute.IsMatch(path))
                {
                    return(matchedRoutes);
                }

                PortalTrace.Warn("Routes", "GetMatchedRoutes", "Using default '/controller/action/parameters' route.");
                matchedRoutes.Add(defaultRoute);
            }

            if (secondaryRoutes != null && secondaryRoutes.Count > 0)
            {
                foreach (KeyValuePair <string, Route> pair in secondaryRoutes)
                {
                    Route route = pair.Value;
                    if (!route.IsMatch(path))
                    {
                        continue;
                    }

                    PortalTrace.Write("Routes", "GetMatchedRoutes", "Found matching secondary route {0}", route.RouteName);
                    matchedRoutes.Add(route);
                }
            }

            PortalTrace.Write("Routes", "GetMatchedRoutes", "End GetMatchedRoutes. {1} routes found", path, matchedRoutes.Count);

            return(matchedRoutes);
        }