Esempio n. 1
0
        protected void ReRegisterRoutes()
        {
            RouteCollection routes         = RouteTable.Routes;
            var             routesToDelete = routes.OfType <Route>().Where(r => r.RouteHandler is Rock.Web.RockRouteHandler).ToList();

            foreach (Route oldRoute in routesToDelete)
            {
                routes.Remove(oldRoute);
            }


            PageRouteService pageRouteService = new PageRouteService(new Rock.Data.RockContext());

            var routesToInsert = new RouteCollection();

            // Add ignore rule for asp.net ScriptManager files.
            routesToInsert.Ignore("{resource}.axd/{*pathInfo}");

            //Add page routes, order is very important here as IIS takes the first match
            IOrderedEnumerable <PageRoute> pageRoutes = pageRouteService.Queryable().AsNoTracking().ToList().OrderBy(r => r.Route, StringComparer.OrdinalIgnoreCase);

            foreach (var pageRoute in pageRoutes)
            {
                routesToInsert.AddPageRoute(pageRoute.Route, new Rock.Web.PageAndRouteId {
                    PageId = pageRoute.PageId, RouteId = pageRoute.Id
                });
            }

            // Add a default page route
            routesToInsert.Add(new Route("page/{PageId}", new Rock.Web.RockRouteHandler()));

            // Add a default route for when no parameters are passed
            routesToInsert.Add(new Route("", new Rock.Web.RockRouteHandler()));

            // Add a default route for shortlinks
            routesToInsert.Add(new Route("{shortlink}", new Rock.Web.RockRouteHandler()));

            // Insert the list of routes to the beginning of the Routes so that PageRoutes, etc are before OdataRoutes. Even when Re-Registering routes
            // Since we are inserting at 0, reverse the list to they end up in the original order
            foreach (var pageRoute in routesToInsert.Reverse())
            {
                routes.Insert(0, pageRoute);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes(RockContext rockContext, RouteCollection routes)
        {
            routes.Clear();

            PageRouteService pageRouteService = new PageRouteService(rockContext);

            // find each page that has defined a custom routes.
            foreach (PageRoute pageRoute in pageRouteService.Queryable())
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute(pageRoute);
            }

            // Add a default page route
            routes.Add(new Route("page/{PageId}", new Rock.Web.RockRouteHandler()));

            // Add a default route for when no parameters are passed
            routes.Add(new Route("", new Rock.Web.RockRouteHandler()));
        }
Esempio n. 3
0
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes(RouteCollection routes)
        {
            PageRouteService pageRouteService = new PageRouteService();

            // find each page that has defined a custom routes.
            foreach (PageRoute pageRoute in pageRouteService.Queryable())
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute(pageRoute);
            }

            // Add any custom api routes
            foreach (var type in Rock.Reflection.FindTypes(
                         typeof(Rock.Rest.IHasCustomRoutes),
                         new DirectoryInfo[] { new DirectoryInfo(Server.MapPath("~/bin")), new DirectoryInfo(Server.MapPath("~/Plugins")) }))
            {
                var controller = (Rock.Rest.IHasCustomRoutes)Activator.CreateInstance(type.Value);
                if (controller != null)
                {
                    controller.AddRoutes(routes);
                }
            }

            // Add API Service routes
            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = System.Web.Http.RouteParameter.Optional }
                );

            // Add a default page route
            routes.Add(new Route("page/{PageId}", new Rock.Web.RockRouteHandler()));

            // Add a default route for when no parameters are passed
            routes.Add(new Route("", new Rock.Web.RockRouteHandler()));
        }
Esempio n. 4
0
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes( RouteCollection routes )
        {
            PageRouteService pageRouteService = new PageRouteService();

            // find each page that has defined a custom routes.
            foreach ( PageRoute pageRoute in pageRouteService.Queryable() )
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute( pageRoute );
            }

            // Add API route for dataviews
            routes.MapHttpRoute(
                name: "DataViewApi",
                routeTemplate: "api/{controller}/DataView/{id}",
                defaults: new
                {
                    action = "DataView"
                }
            );

            // Add any custom api routes
            foreach ( var type in Rock.Reflection.FindTypes(
                typeof( Rock.Rest.IHasCustomRoutes ) ) )
            {
                var controller = (Rock.Rest.IHasCustomRoutes)Activator.CreateInstance( type.Value );
                if ( controller != null )
                    controller.AddRoutes( routes );
            }

            // Add Default API Service routes
            // Instead of being able to use one default route that gets action from http method, have to 
            // have a default route for each method so that other actions do not match the default (i.e. DataViews)
            routes.MapHttpRoute(
                name: "DefaultApiGet",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
                {
                    action = "GET",
                    id = System.Web.Http.RouteParameter.Optional
                },
                constraints: new
                {
                    httpMethod = new HttpMethodConstraint( new string[] { "GET" } )
                }
            );

            routes.MapHttpRoute(
               name: "DefaultApiPut",
               routeTemplate: "api/{controller}/{id}",
               defaults: new
               {
                   action = "PUT",
                   id = System.Web.Http.RouteParameter.Optional
               },
               constraints: new
               {
                   httpMethod = new HttpMethodConstraint( new string[] { "PUT" } )
               }
           );

            routes.MapHttpRoute(
                name: "DefaultApiPost",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
                {
                    action = "POST",
                    id = System.Web.Http.RouteParameter.Optional
                },
                constraints: new
                {
                    httpMethod = new HttpMethodConstraint( new string[] { "POST" } )
                }
            );

            routes.MapHttpRoute(
                name: "DefaultApiDelete",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
                {
                    action = "DELETE",
                    id = System.Web.Http.RouteParameter.Optional
                },
                constraints: new
                {
                    httpMethod = new HttpMethodConstraint( new string[] { "DELETE" } )
                }
            );

            // Add a default page route
            routes.Add( new Route( "page/{PageId}", new Rock.Web.RockRouteHandler() ) );

            // Add a default route for when no parameters are passed
            routes.Add( new Route( "", new Rock.Web.RockRouteHandler() ) );
        }
Esempio n. 5
0
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes( RouteCollection routes )
        {
            PageRouteService pageRouteService = new PageRouteService();

            // find each page that has defined a custom routes.
            foreach ( PageRoute pageRoute in pageRouteService.Queryable() )
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute( pageRoute );
            }

            // Add any custom api routes
            foreach ( var type in Rock.Reflection.FindTypes(
                typeof( Rock.Rest.IHasCustomRoutes ),
                new DirectoryInfo[] { new DirectoryInfo( Server.MapPath( "~/bin" ) ), new DirectoryInfo( Server.MapPath( "~/Plugins" ) ) } ) )
            {
                var controller = (Rock.Rest.IHasCustomRoutes)Activator.CreateInstance( type.Value );
                if ( controller != null )
                    controller.AddRoutes( routes );
            }

            // Add API Service routes
            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = System.Web.Http.RouteParameter.Optional }
            );

            // Add a default page route
            routes.Add( new Route( "page/{PageId}", new Rock.Web.RockRouteHandler() ) );

            // Add a default route for when no parameters are passed
            routes.Add( new Route( "", new Rock.Web.RockRouteHandler() ) );
        }
Esempio n. 6
0
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes(RouteCollection routes)
        {
            PageRouteService pageRouteService = new PageRouteService();

            // find each page that has defined a custom routes.
            foreach (PageRoute pageRoute in pageRouteService.Queryable())
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute(pageRoute);
            }

            // Add API route for dataviews
            routes.MapHttpRoute(
                name: "DataViewApi",
                routeTemplate: "api/{controller}/DataView/{id}",
                defaults: new
            {
                action = "DataView"
            }
                );

            // Add any custom api routes
            foreach (var type in Rock.Reflection.FindTypes(
                         typeof(Rock.Rest.IHasCustomRoutes)))
            {
                var controller = (Rock.Rest.IHasCustomRoutes)Activator.CreateInstance(type.Value);
                if (controller != null)
                {
                    controller.AddRoutes(routes);
                }
            }

            // Add Default API Service routes
            // Instead of being able to use one default route that gets action from http method, have to
            // have a default route for each method so that other actions do not match the default (i.e. DataViews)
            routes.MapHttpRoute(
                name: "DefaultApiGet",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
            {
                action = "GET",
                id     = System.Web.Http.RouteParameter.Optional
            },
                constraints: new
            {
                httpMethod = new HttpMethodConstraint(new string[] { "GET" })
            }
                );

            routes.MapHttpRoute(
                name: "DefaultApiPut",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
            {
                action = "PUT",
                id     = System.Web.Http.RouteParameter.Optional
            },
                constraints: new
            {
                httpMethod = new HttpMethodConstraint(new string[] { "PUT" })
            }
                );

            routes.MapHttpRoute(
                name: "DefaultApiPost",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
            {
                action = "POST",
                id     = System.Web.Http.RouteParameter.Optional
            },
                constraints: new
            {
                httpMethod = new HttpMethodConstraint(new string[] { "POST" })
            }
                );

            routes.MapHttpRoute(
                name: "DefaultApiDelete",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
            {
                action = "DELETE",
                id     = System.Web.Http.RouteParameter.Optional
            },
                constraints: new
            {
                httpMethod = new HttpMethodConstraint(new string[] { "DELETE" })
            }
                );

            // Add a default page route
            routes.Add(new Route("page/{PageId}", new Rock.Web.RockRouteHandler()));

            // Add a default route for when no parameters are passed
            routes.Add(new Route("", new Rock.Web.RockRouteHandler()));
        }
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes( RockContext rockContext, RouteCollection routes )
        {
            routes.Clear();

            PageRouteService pageRouteService = new PageRouteService( rockContext );

            // find each page that has defined a custom routes.
            foreach ( PageRoute pageRoute in pageRouteService.Queryable() )
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute( pageRoute );
            }

            // Add a default page route
            routes.Add( new Route( "page/{PageId}", new Rock.Web.RockRouteHandler() ) );

            // Add a default route for when no parameters are passed
            routes.Add( new Route( "", new Rock.Web.RockRouteHandler() ) );
        }
Esempio n. 8
0
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes( RockContext rockContext, RouteCollection routes )
        {
            routes.Clear();

            PageRouteService pageRouteService = new PageRouteService( rockContext );

            // Add ingore rule for asp.net ScriptManager files.
            routes.Ignore("{resource}.axd/{*pathInfo}");

            // Add page routes
            foreach ( var route in pageRouteService
                .Queryable().AsNoTracking()
                .GroupBy( r => r.Route )
                .Select( s => new {
                    Name = s.Key,
                    Pages = s.Select( pr => new Rock.Web.PageAndRouteId { PageId = pr.PageId, RouteId = pr.Id } ).ToList()
                } )
                .ToList() )
            {
                routes.AddPageRoute( route.Name, route.Pages );
            }

            // Add a default page route
            routes.Add( new Route( "page/{PageId}", new Rock.Web.RockRouteHandler() ) );

            // Add a default route for when no parameters are passed
            routes.Add( new Route( "", new Rock.Web.RockRouteHandler() ) );
        }