示例#1
0
        public static Control AddUserControl(Control container, ContentItem item)
        {
            PathData path = item.FindPath(PathData.DefaultAction);

            if (!path.IsEmpty())
            {
                return(AddUserControl(path.TemplateUrl, container, item));
            }
            return(null);
        }
示例#2
0
        private RouteData GetRouteDataForPath(HttpRequestBase request)
        {
            //On a multi-lingual site with separate domains per language,
            //the full url (with host) should be passed to UrlParser.ResolvePath():
            string   host = (request.Url.IsDefaultPort) ? request.Url.Host : request.Url.Authority;
            var      url  = new Url(request.Url.Scheme, host, request.RawUrl);
            PathData path = engine.Resolve <RequestPathProvider>().ResolveUrl(url);

            if (!path.IsEmpty() && path.IsRewritable && StopRewritableItems)
            {
                return(new RouteData(this, new StopRoutingHandler()));
            }

            var page = path.CurrentPage;

            var actionName = path.Action;

            if (string.IsNullOrEmpty(actionName))
            {
                actionName = request.QueryString["action"] ?? "Index";
            }

            if (!string.IsNullOrEmpty(request.QueryString[PathData.PageQueryKey]))
            {
                int pageId;
                if (int.TryParse(request.QueryString[PathData.PageQueryKey], out pageId))
                {
                    path.CurrentPage = page = engine.Persister.Get(pageId);
                }
            }

            ContentItem part = null;

            if (!string.IsNullOrEmpty(request.QueryString[PathData.PartQueryKey]))
            {
                // part in query string is used to render a part
                int partId;
                if (int.TryParse(request.QueryString[PathData.PartQueryKey], out partId))
                {
                    path.CurrentItem = part = engine.Persister.Get(partId);
                }
            }

            if (!string.IsNullOrEmpty(request.QueryString[PathData.ItemQueryKey]))
            {
                // this is a discrepancy between mvc and the legacy
                // in mvc the item query key doesn't route to the item, it's a marker
                // the urlparser however parses the item query key and passes the item as current in pathdata
                // hence this somewhat strange sidestepping
                int itemId;
                if (int.TryParse(request.QueryString[PathData.ItemQueryKey], out itemId))
                {
                    if (itemId == path.ID)
                    {
                        // we have an item id and it matches the path data we found via url parser
                        if (part == null || part.ID != itemId)
                        {
                            // it hasn't been changed by a specific part query string so we reset it
                            path.CurrentItem = path.CurrentPage;
                        }
                    }
                }
            }

            if (page == null && part == null)
            {
                return(null);
            }

            path.CurrentPage = page ?? part.ClosestPage();

            var controllerName = controllerMapper.GetControllerName((part ?? page).GetContentType());

            if (controllerName == null)
            {
                return(null);
            }

            if (actionName == null || !controllerMapper.ControllerHasAction(controllerName, actionName))
            {
                return(null);
            }

            var data = new RouteData(this, routeHandler);

            foreach (var defaultPair in innerRoute.Defaults)
            {
                data.Values[defaultPair.Key] = defaultPair.Value;
            }
            foreach (var tokenPair in innerRoute.DataTokens)
            {
                data.DataTokens[tokenPair.Key] = tokenPair.Value;
            }

            RouteExtensions.ApplyCurrentPath(data, controllerName, actionName, path);
            data.DataTokens[ContentEngineKey] = engine;

            return(data);
        }