private static void InitModuleMenuItem(MenuItem menuItem, UrlHelper moduleUrlHelper, string moduleName, string scaffoldController, string scaffoldAction, RouteValueDictionary scaffoldRouteValues, string siteName) { var routeValues = new RouteValueDictionary(menuItem.RouteValues); routeValues.Merge("SiteName", siteName); routeValues.Merge("ModuleName", moduleName); var moduleUrl = moduleUrlHelper.Action(menuItem.Action, menuItem.Controller, routeValues); moduleUrl = ModuleUrlHelper.RemoveApplicationPath(moduleUrl, moduleUrlHelper.RequestContext.HttpContext.Request.ApplicationPath); menuItem.Controller = scaffoldController; menuItem.Action = scaffoldAction; menuItem.RouteValues = scaffoldRouteValues != null ? new RouteValueDictionary(scaffoldRouteValues) : new RouteValueDictionary(); menuItem.RouteValues.Merge("ModuleUrl", moduleUrl); menuItem.RouteValues.Merge("ModuleName", moduleName); if (menuItem.Items != null && menuItem.Items.Count > 0) { foreach (var item in menuItem.Items) { InitModuleMenuItem(item, moduleUrlHelper, moduleName, scaffoldController, scaffoldAction, scaffoldRouteValues, siteName); } } var isCurrentModule = moduleUrlHelper.RequestContext.GetRequestValue("ModuleName").EqualsOrNullEmpty(moduleName, StringComparison.OrdinalIgnoreCase); menuItem.IsActive = menuItem.IsActive && isCurrentModule; menuItem.IsCurrent = isCurrentModule; }
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) { var virtualPath = base.GetVirtualPath(requestContext, values); if (requestContext.HttpContext is ModuleHttpContext) { var moduleUrl = virtualPath.VirtualPath; ModuleHttpContext httpContext = (ModuleHttpContext)(requestContext.HttpContext); var moduleContext = httpContext.ModuleContext; if (Page_Context.Current.Initialized) { var modulePositionId = Page_Context.Current.PageRequestContext.ModuleUrlContext.GetModulePositionIdForUrl(moduleContext.ModulePosition.ModuleName, moduleContext.ModulePosition.PagePositionId, values); var encodedModuleUrl = ModuleUrlHelper.Encode(moduleUrl); var routeValues = Page_Context.Current.PageRequestContext.ModuleUrlContext.GetRouteValuesWithModuleUrl(modulePositionId, encodedModuleUrl, moduleContext.ModulePosition.Exclusive); virtualPath.VirtualPath = Page_Context.Current.FrontUrl.PageUrl(Page_Context.Current.PageRequestContext.Page.FullName, routeValues).ToString().TrimStart('/'); } else { ModuleRequestContext moduleRequestContext = (ModuleRequestContext)requestContext; UrlHelper pageUrl = new UrlHelper(moduleRequestContext.PageControllerContext.RequestContext); virtualPath.VirtualPath = pageUrl.Action(moduleRequestContext.PageControllerContext.RequestContext.RouteData.Values["action"].ToString() , moduleRequestContext.PageControllerContext.RequestContext.AllRouteValues().Merge("ModuleUrl", moduleUrl)).TrimStart('/'); } } return(virtualPath); }
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) { var virtualPath = base.GetVirtualPath(requestContext, values); if (requestContext.HttpContext is ModuleHttpContext && virtualPath != null) { var moduleUrl = virtualPath.VirtualPath; ModuleHttpContext httpContext = (ModuleHttpContext)(requestContext.HttpContext); var moduleContext = httpContext.ModuleContext; var mergedValues = Kooboo.Web.Mvc.RouteValuesHelpers.MergeRouteValues(null, null, this.Defaults, values, true); if (Page_Context.Current.Initialized) { Page page = null; var modulePositionId = Page_Context.Current.PageRequestContext.ModuleUrlContext.GetModulePositionIdForUrl(moduleContext.ModulePosition, mergedValues, out page); var encodedModuleUrl = ModuleUrlHelper.Encode(moduleUrl); var routeValues = Page_Context.Current.PageRequestContext.ModuleUrlContext.GetRouteValuesWithModuleUrl(modulePositionId, encodedModuleUrl, moduleContext.ModulePosition.Exclusive); var pageUrl = Page_Context.Current.FrontUrl.PageUrl(page.FullName, routeValues).ToString(); var routeVirtualPath = pageUrl; if (Uri.IsWellFormedUriString(pageUrl, UriKind.Absolute)) { routeVirtualPath = new Uri(routeVirtualPath).PathAndQuery; } virtualPath.VirtualPath = routeVirtualPath.TrimStart('/'); } else { ModuleRequestContext moduleRequestContext = (ModuleRequestContext)requestContext; UrlHelper pageUrl = new UrlHelper(moduleRequestContext.PageControllerContext.RequestContext); virtualPath.VirtualPath = pageUrl.Action(moduleRequestContext.PageControllerContext.RequestContext.RouteData.Values["action"].ToString() , moduleRequestContext.PageControllerContext.RequestContext.AllRouteValues().Merge("ModuleUrl", moduleUrl)).TrimStart('/'); } } return(virtualPath); }