private SiteMapNode GetParentNodeFromNode(DXInfo.Models.aspnet_Sitemap item) { if (!_nodes.ContainsKey(item.ParentCode)) { throw new ProviderException(string.Format("无效父节点Code={0},Title={1}", item.Code, item.Title)); } return(_nodes[item.ParentCode]); }
private SiteMapNode CreateSiteMapFromRow(DXInfo.Models.aspnet_Sitemap item) { if (_nodes.ContainsKey(item.Code)) { throw new ProviderException(string.Format("重复节点Code={0},Title={1}", item.Code, item.Title)); } SiteMapNode node = new SiteMapNode(this, item.Code); node["IsAuthorize"] = item.IsAuthorize.ToString(); if (!string.IsNullOrEmpty(item.Url)) { node.Title = string.IsNullOrEmpty(item.Title) ? null : item.Title; node.Description = string.IsNullOrEmpty(item.Description) ? null : item.Description; node.Url = string.IsNullOrEmpty(item.Url) ? null : item.Url; } else { node.Title = string.IsNullOrEmpty(item.Title) ? null : item.Title; node.Description = string.IsNullOrEmpty(item.Description) ? null : item.Description; IDictionary <string, object> routeValues = new Dictionary <string, object>(); if (string.IsNullOrEmpty(item.Controller)) { routeValues.Add("controller", "Home"); } else { routeValues.Add("controller", item.Controller); } if (string.IsNullOrEmpty(item.Action)) { routeValues.Add("action", "Index"); } else { routeValues.Add("action", item.Action); } if (!string.IsNullOrEmpty(item.ParaId)) { routeValues.Add("id", item.ParaId); } HttpContextWrapper httpContext = new HttpContextWrapper(HttpContext.Current); RouteData routeData = RouteTable.Routes.GetRouteData(httpContext); if (routeData != null) { VirtualPathData virtualPath = routeData.Route.GetVirtualPath(new RequestContext(httpContext, routeData), new RouteValueDictionary(routeValues)); if (virtualPath != null) { node.Url = "~/" + virtualPath.VirtualPath; } } } _nodes.Add(item.Code, node); return(node); }