public MatchedPage GetMatchedPage(MatchedSite matchedSite)
        {
            var siteUrl = matchedSite.SiteUrl;

            if (matchedSite.IsHomePage) // home page
            {
                var homePage = GetOnlinePages(matchedSite.Site.Id).FirstOrDefault(i => i.ParentId == null);
                return(new MatchedPage
                {
                    Page = homePage,
                    RouteValues = new RouteValueDictionary()
                });
            }
            else
            {
                var subFolder = siteUrl.GetSubFolder();
                if (!String.IsNullOrWhiteSpace(subFolder))
                {
                    subFolder += "/";
                }

                var routes = new RouteCollection();
                var pages  = GetOnlinePages(matchedSite.Site.Id);
                foreach (var page in pages)
                {
                    routes.Add(new Route(subFolder + page.Url, null, null,
                                         new RouteValueDictionary {
                        { "pageId", page.Id }
                    },
                                         new MvcRouteHandler()));
                }

                var data = routes.GetRouteData(_requestContext.HttpContext);
                if (data != null)
                {
                    var pageId = (int)data.DataTokens["pageId"];
                    return(new MatchedPage
                    {
                        Page = pages.First(i => i.Id == pageId),
                        RouteValues = data.Values
                    });
                }
            }

            return(null);
        }
Beispiel #2
0
        public MatchedPage GetMatchedPage(MatchedSite matchedSite)
        {
            var siteUrl = matchedSite.SiteUrl;
            if (matchedSite.IsHomePage) // home page
            {
                var homePage = GetOnlinePages(matchedSite.Site.Id).FirstOrDefault(i => i.ParentId == null);
                return new MatchedPage
                {
                    Page = homePage,
                    RouteValues = new RouteValueDictionary()
                };
            }
            else
            {
                var subFolder = siteUrl.GetSubFolder();
                if (!String.IsNullOrWhiteSpace(subFolder))
                {
                    subFolder += "/";
                }

                var routes = new RouteCollection();
                var pages = GetOnlinePages(matchedSite.Site.Id);
                foreach (var page in pages)
                {
                    routes.Add(new Route(subFolder + page.Url, null, null,
                        new RouteValueDictionary { { "pageId", page.Id } },
                        new MvcRouteHandler()));
                }

                var data = routes.GetRouteData(_requestContext.HttpContext);
                if (data != null)
                {
                    var pageId = (int)data.DataTokens["pageId"];
                    return new MatchedPage
                    {
                        Page = pages.First(i => i.Id == pageId),
                        RouteValues = data.Values
                    };
                }
            }

            return null;
        }