Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PageReference"/> class from a url.
        /// </summary>
        /// <param name="uri">The URI e.g.: new Uri( ResolveRockUrlIncludeRoot("~/Person/5")</param>
        /// <param name="applicationPath">The application path e.g.: HttpContext.Current.Request.ApplicationPath</param>
        public PageReference(Uri uri, string applicationPath)
        {
            Parameters = new Dictionary <string, string>();

            var routeInfo = new Rock.Web.RouteInfo(uri, applicationPath);

            if (routeInfo != null)
            {
                if (routeInfo.RouteData.Values["PageId"] != null)
                {
                    PageId = routeInfo.RouteData.Values["PageId"].ToString().AsInteger();
                }

                else if (routeInfo.RouteData.DataTokens["PageRoutes"] != null)
                {
                    var pages = routeInfo.RouteData.DataTokens["PageRoutes"] as List <PageAndRouteId>;
                    if (pages != null && pages.Count > 0)
                    {
                        if (pages.Count == 1)
                        {
                            var pageAndRouteId = pages.First();
                            PageId  = pageAndRouteId.PageId;
                            RouteId = pageAndRouteId.RouteId;
                        }
                        else
                        {
                            SiteCache site = SiteCache.GetSiteByDomain(uri.Host);
                            if (site != null)
                            {
                                foreach (var pageAndRouteId in pages)
                                {
                                    var pageCache = PageCache.Get(pageAndRouteId.PageId);
                                    if (pageCache != null && pageCache.Layout != null && pageCache.Layout.SiteId == site.Id)
                                    {
                                        PageId  = pageAndRouteId.PageId;
                                        RouteId = pageAndRouteId.RouteId;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    foreach (var routeParm in routeInfo.RouteData.Values)
                    {
                        Parameters.Add(routeParm.Key, (string)routeParm.Value);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PageReference"/> class from a url.
        /// </summary>
        /// <param name="uri">The URI e.g.: new Uri( ResolveRockUrlIncludeRoot("~/Person/5")</param>
        /// <param name="applicationPath">The application path e.g.: HttpContext.Current.Request.ApplicationPath</param>
        public PageReference(Uri uri, string applicationPath)
        {
            Parameters = new Dictionary <string, string>();

            var routeInfo = new Rock.Web.RouteInfo(uri, applicationPath);

            if (routeInfo != null)
            {
                if (routeInfo.RouteData.Values["PageId"] != null)
                {
                    PageId = routeInfo.RouteData.Values["PageId"].ToString().AsInteger();
                }
                else if (routeInfo.RouteData.DataTokens["PageId"] != null)
                {
                    PageId  = routeInfo.RouteData.DataTokens["PageId"].ToString().AsInteger();
                    RouteId = routeInfo.RouteData.DataTokens["RouteId"].ToString().AsInteger();

                    foreach (var routeParm in routeInfo.RouteData.Values)
                    {
                        Parameters.Add(routeParm.Key, (string)routeParm.Value);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PageReference"/> class from a url.
        /// </summary>
        /// <param name="uri">The URI e.g.: new Uri( ResolveRockUrlIncludeRoot("~/Person/5")</param>
        /// <param name="applicationPath">The application path e.g.: HttpContext.Current.Request.ApplicationPath</param>
        public PageReference( Uri uri, string applicationPath )
        {
            Parameters = new Dictionary<string, string>();

            var routeInfo = new Rock.Web.RouteInfo( uri, applicationPath );
            if ( routeInfo != null )
            {
                if ( routeInfo.RouteData.Values["PageId"] != null )
                {
                    PageId = routeInfo.RouteData.Values["PageId"].ToString().AsInteger();
                }

                else if ( routeInfo.RouteData.DataTokens["PageRoutes"] != null )
                {
                    var pages = routeInfo.RouteData.DataTokens["PageRoutes"] as List<PageAndRouteId>;
                    if ( pages != null && pages.Count > 0 )
                    {
                        if ( pages.Count == 1 )
                        {
                            var pageAndRouteId = pages.First();
                            PageId = pageAndRouteId.PageId;
                            RouteId = pageAndRouteId.RouteId;
                        }
                        else
                        {
                            SiteCache site = SiteCache.GetSiteByDomain( uri.Host );
                            if ( site != null )
                            {
                                foreach( var pageAndRouteId in pages )
                                {
                                    var pageCache = PageCache.Read( pageAndRouteId.PageId );
                                    if ( pageCache != null && pageCache.Layout != null && pageCache.Layout.SiteId == site.Id )
                                    {
                                        PageId = pageAndRouteId.PageId;
                                        RouteId = pageAndRouteId.RouteId;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    foreach ( var routeParm in routeInfo.RouteData.Values )
                    {
                        Parameters.Add( routeParm.Key, (string)routeParm.Value );
                    }
                }
            }
        }