public string GetUrl(ContentAddress ca) { RouteValueDictionary rvs = new RouteValueDictionary(); rvs.Add("controller", ca.Controller); rvs.Add("action", ca.Action); ControllerInfo cInfo = GetController((string)rvs["controller"]);; if (cInfo == null) { throw new MissingControllerException("Can't find controller " + ca.Controller); } for (int i = 0; i < Math.Min(cInfo.SignificantRouteKeys.Count, ca.Subindexes.Count); i++) { rvs.Add(cInfo.SignificantRouteKeys[i], ca.Subindexes[i]); } UrlPattern patt = cInfo.UrlPatterns.FirstOrDefault(up => up.Matches(rvs)); if (patt == null) { throw new StructureException("No matching pattern found on controller " + ca.Controller); } return(patt.BuildUrl(rvs)); }
public string GetUrl(RouteValueDictionary rvs) { if (!rvs.ContainsKey("controller")) { throw new ArgumentException("Route values for GetUrl missing controller entry"); } ControllerInfo cInfo = GetController((string)rvs["controller"]); if (cInfo == null) { throw new MissingControllerException("Can't find controller " + (string)rvs["controller"]); } UrlPattern patt = cInfo.UrlPatterns.FirstOrDefault(up => up.Matches(rvs)); if (patt == null) { throw new StructureException("No matching pattern found on controller " + cInfo.Controller.Name); } return(patt.BuildUrl(rvs)); }