Exemplo n.º 1
0
        /// <summary>
        /// Create the routes for the area
        /// </summary>
        /// <param name="context"></param>
        /// <remarks>
        /// By using the context to register the routes it means that the area is already applied to them all
        /// and that the namespaces searched for the controllers are ONLY the ones specified.
        /// </remarks>
        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Umbraco_preview",
                _globalSettings.GetUmbracoMvcArea() + "/preview/{action}/{editor}",
                new { controller = "Preview", action = "Index", editor = UrlParameter.Optional },
                new[] { "Umbraco.Web.Editors" });

            context.MapRoute(
                "Umbraco_back_office",
                _globalSettings.GetUmbracoMvcArea() + "/{action}/{id}",
                new { controller = "BackOffice", action = "Default", id = UrlParameter.Optional },
                //limit the action/id to only allow characters - this is so this route doesn't hog all other
                // routes like: /umbraco/channels/word.aspx, etc...
                new
            {
                action = @"[a-zA-Z]*",
                id     = @"[a-zA-Z]*"
            },
                new[] { typeof(BackOfficeController).Namespace });

            //Create the REST/web/script service routes
            context.MapRoute(
                "Umbraco_web_services",
                _globalSettings.GetUmbracoMvcArea() + "/RestServices/{controller}/{action}/{id}",
                new { controller = "SaveFileController", action = "Index", id = UrlParameter.Optional },
                //look in this namespace for controllers
                new[] { "Umbraco.Web.WebServices" });
        }
        // internal for tests
        internal static void CreateRoutes(
            IUmbracoContextAccessor umbracoContextAccessor,
            IGlobalSettings globalSettings,
            SurfaceControllerTypeCollection surfaceControllerTypes,
            UmbracoApiControllerTypeCollection apiControllerTypes)
        {
            var umbracoPath = globalSettings.GetUmbracoMvcArea();

            // create the front-end route
            var defaultRoute = RouteTable.Routes.MapRoute(
                "Umbraco_default",
                umbracoPath + "/RenderMvc/{action}/{id}",
                new { controller = "RenderMvc", action = "Index", id = UrlParameter.Optional }
                );

            defaultRoute.RouteHandler = new RenderRouteHandler(umbracoContextAccessor, ControllerBuilder.Current.GetControllerFactory());

            // register install routes
            RouteTable.Routes.RegisterArea <UmbracoInstallArea>();

            // register all back office routes
            RouteTable.Routes.RegisterArea(new BackOfficeArea(globalSettings));

            // plugin controllers must come first because the next route will catch many things
            RoutePluginControllers(globalSettings, surfaceControllerTypes, apiControllerTypes);
        }
Exemplo n.º 3
0
 public void Initialize()
 {
     RouteTable.Routes.MapRoute("BentoApiIndex", _globalSettings.GetUmbracoMvcArea() + "/backoffice/Api/Bento/{action}/{id}", new
     {
         controller = "BentoApi",
         action     = "Index",
         id         = UrlParameter.Optional
     });
 }
        /// <summary>
        /// Configures SignalR.
        /// </summary>
        /// <param name="app">The app builder.</param>
        /// <param name="globalSettings"></param>
        public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings)
        {
            var umbracoPath = globalSettings.GetUmbracoMvcArea();
            var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr";

            return(app.MapSignalR(signalrPath, new HubConfiguration {
                EnableDetailedErrors = true
            }));
        }
        private void Configure(IAppBuilder app)
        {
            var path = $"/{_globalSettings.GetUmbracoMvcArea()}/graphql";

            app.UseUmbracoGraphQL(path, _factory, opts =>
            {
                opts.Debug              = HostingEnvironment.IsDevelopmentEnvironment;
                opts.EnableMetrics      = true;
                opts.EnableMiniProfiler = false;
                opts.EnablePlayground   = true;
            });
        }
        private static void RoutePluginControllers(
            IGlobalSettings globalSettings,
            SurfaceControllerTypeCollection surfaceControllerTypes,
            UmbracoApiControllerTypeCollection apiControllerTypes)
        {
            var umbracoPath = globalSettings.GetUmbracoMvcArea();

            // need to find the plugin controllers and route them
            var pluginControllers = surfaceControllerTypes.Concat(apiControllerTypes).ToArray();

            // local controllers do not contain the attribute
            var localControllers = pluginControllers.Where(x => PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace());

            foreach (var s in localControllers)
            {
                if (TypeHelper.IsTypeAssignableFrom <SurfaceController>(s))
                {
                    RouteLocalSurfaceController(s, umbracoPath);
                }
                else if (TypeHelper.IsTypeAssignableFrom <UmbracoApiController>(s))
                {
                    RouteLocalApiController(s, umbracoPath);
                }
            }

            // get the plugin controllers that are unique to each area (group by)
            var pluginSurfaceControlleres = pluginControllers.Where(x => PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace() == false);
            var groupedAreas = pluginSurfaceControlleres.GroupBy(controller => PluginController.GetMetadata(controller).AreaName);

            // loop through each area defined amongst the controllers
            foreach (var g in groupedAreas)
            {
                // create & register an area for the controllers (this will throw an exception if all controllers are not in the same area)
                var pluginControllerArea = new PluginControllerArea(globalSettings, g.Select(PluginController.GetMetadata));
                RouteTable.Routes.RegisterArea(pluginControllerArea);
            }
        }
Exemplo n.º 7
0
        public uSyncBackofficeComponent(
            IGlobalSettings globalSettings,
            uSyncConfig uSyncConfig,
            SyncHandlerFactory handlerFactory,
            IProfilingLogger logger,
            SyncFileService fileService,
            uSyncService uSyncService,
            IRuntimeState runtimeState,
            IUmbracoContextFactory umbracoContextFactory)
        {
            uSyncSettings = uSyncConfig.Settings;

            UmbracoMvcArea = globalSettings.GetUmbracoMvcArea();

            this.runtimeState = runtimeState;
            this.logger       = logger;

            this.handlerFactory = handlerFactory;

            this.syncFileService = fileService;
            this.uSyncService    = uSyncService;

            this.umbracoContextFactory = umbracoContextFactory;
        }
Exemplo n.º 8
0
        ///  <summary>
        ///  Checks if the current uri is a back office request
        ///  </summary>
        ///  <param name="url"></param>
        ///  <param name="applicationPath">
        ///  The current application path or VirtualPath
        ///  </param>
        /// <param name="globalSettings"></param>
        /// <returns></returns>
        ///  <remarks>
        ///  There are some special routes we need to check to properly determine this:
        ///
        ///      If any route has an extension in the path like .aspx = back office
        ///
        ///      These are def back office:
        ///          /Umbraco/BackOffice     = back office
        ///          /Umbraco/Preview        = back office
        ///      If it's not any of the above, and there's no extension then we cannot determine if it's back office or front-end
        ///      so we can only assume that it is not back office. This will occur if people use an UmbracoApiController for the backoffice
        ///      but do not inherit from UmbracoAuthorizedApiController and do not use [IsBackOffice] attribute.
        ///
        ///      These are def front-end:
        ///          /Umbraco/Surface        = front-end
        ///          /Umbraco/Api            = front-end
        ///      But if we've got this far we'll just have to assume it's front-end anyways.
        ///
        ///  </remarks>
        internal static bool IsBackOfficeRequest(this Uri url, string applicationPath, IGlobalSettings globalSettings)
        {
            applicationPath = applicationPath ?? string.Empty;

            var fullUrlPath = url.AbsolutePath.TrimStart(new[] { '/' });
            var appPath     = applicationPath.TrimStart(new[] { '/' });
            var urlPath     = fullUrlPath.TrimStart(appPath).EnsureStartsWith('/');

            //check if this is in the umbraco back office
            var isUmbracoPath = urlPath.InvariantStartsWith(globalSettings.Path.EnsureStartsWith('/').TrimStart(appPath.EnsureStartsWith('/')).EnsureStartsWith('/'));

            //if not, then def not back office
            if (isUmbracoPath == false)
            {
                return(false);
            }

            //if its the normal /umbraco path
            if (urlPath.InvariantEquals("/" + globalSettings.GetUmbracoMvcArea()) ||
                urlPath.InvariantEquals("/" + globalSettings.GetUmbracoMvcArea() + "/"))
            {
                return(true);
            }

            //check for a file extension
            var extension = Path.GetExtension(url.LocalPath);

            //has an extension, def back office
            if (extension.IsNullOrWhiteSpace() == false)
            {
                return(true);
            }
            //check for special case asp.net calls like:
            //  /umbraco/webservices/legacyAjaxCalls.asmx/js which will return a null file extension but are still considered requests with an extension
            if (urlPath.InvariantContains(".asmx/") ||
                urlPath.InvariantContains(".aspx/") ||
                urlPath.InvariantContains(".ashx/") ||
                urlPath.InvariantContains(".axd/") ||
                urlPath.InvariantContains(".svc/"))
            {
                return(true);
            }

            //check for special back office paths
            if (urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/BackOffice/") ||
                urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/Preview/"))
            {
                return(true);
            }

            //check for special front-end paths
            if (urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/Surface/") ||
                urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/Api/"))
            {
                return(false);
            }

            //if its none of the above, we will have to try to detect if it's a PluginController route, we can detect this by
            // checking how many parts the route has, for example, all PluginController routes will be routed like
            // Umbraco/MYPLUGINAREA/MYCONTROLLERNAME/{action}/{id}
            // so if the path contains at a minimum 3 parts: Umbraco + MYPLUGINAREA + MYCONTROLLERNAME then we will have to assume it is a
            // plugin controller for the front-end.
            if (urlPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Length >= 3)
            {
                return(false);
            }

            //if its anything else we can assume it's back office
            return(true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a custom individual route for the specified controller plugin. Individual routes
        /// are required by controller plugins to map to a unique URL based on ID.
        /// </summary>
        /// <param name="globalSettings"></param>
        /// <param name="controllerName"></param>
        /// <param name="controllerType"></param>
        /// <param name="routes">An existing route collection</param>
        /// <param name="controllerSuffixName">
        /// The suffix name that the controller name must end in before the "Controller" string for example:
        /// ContentTreeController has a controllerSuffixName of "Tree", this is used for route constraints.
        /// </param>
        /// <param name="defaultAction"></param>
        /// <param name="defaultId"></param>
        /// <param name="area"></param>
        /// <param name="umbracoTokenValue">The DataToken value to set for the 'umbraco' key, this defaults to 'backoffice' </param>
        /// <param name="routeTokens">By default this value is just {action}/{id} but can be modified for things like web api routes</param>
        /// <param name="isMvc">Default is true for MVC, otherwise false for WebAPI</param>
        /// <param name="areaPathPrefix">
        /// If specified will add this string to the path between the umbraco path and the area path name, for example:
        ///     /umbraco/CUSTOMPATHPREFIX/areaname
        /// if not specified, will just route like:
        ///     /umbraco/areaname
        /// </param>
        /// <remarks>
        /// </remarks>
        internal static Route RouteControllerPlugin(this AreaRegistration area,
                                                    IGlobalSettings globalSettings,
                                                    string controllerName, Type controllerType, RouteCollection routes,
                                                    string controllerSuffixName, string defaultAction, object defaultId,
                                                    string umbracoTokenValue = "backoffice",
                                                    string routeTokens       = "{action}/{id}",
                                                    bool isMvc            = true,
                                                    string areaPathPrefix = "")
        {
            if (string.IsNullOrEmpty(controllerName))
            {
                throw new ArgumentNullOrEmptyException(nameof(controllerName));
            }
            if (controllerSuffixName == null)
            {
                throw new ArgumentNullException(nameof(controllerSuffixName));
            }

            if (controllerType == null)
            {
                throw new ArgumentNullException(nameof(controllerType));
            }
            if (routes == null)
            {
                throw new ArgumentNullException(nameof(routes));
            }
            if (defaultId == null)
            {
                throw new ArgumentNullException(nameof(defaultId));
            }

            var umbracoArea = globalSettings.GetUmbracoMvcArea();

            //routes are explicitly named with controller names and IDs
            var url = umbracoArea + "/" +
                      (areaPathPrefix.IsNullOrWhiteSpace() ? "" : areaPathPrefix + "/") +
                      area.AreaName + "/" + controllerName + "/" + routeTokens;

            Route controllerPluginRoute;

            //var meta = PluginController.GetMetadata(controllerType);
            if (isMvc)
            {
                //create a new route with custom name, specified url, and the namespace of the controller plugin
                controllerPluginRoute = routes.MapRoute(
                    //name
                    string.Format("umbraco-{0}-{1}", area.AreaName, controllerName),
                    //url format
                    url,
                    //set the namespace of the controller to match
                    new[] { controllerType.Namespace });

                //set defaults
                controllerPluginRoute.Defaults = new RouteValueDictionary(
                    new Dictionary <string, object>
                {
                    { "controller", controllerName },
                    { "action", defaultAction },
                    { "id", defaultId }
                });
            }
            else
            {
                controllerPluginRoute = routes.MapHttpRoute(
                    //name
                    string.Format("umbraco-{0}-{1}-{2}", "api", area.AreaName, controllerName),
                    //url format
                    url,
                    new { controller = controllerName, id = defaultId });
                //web api routes don't set the data tokens object
                if (controllerPluginRoute.DataTokens == null)
                {
                    controllerPluginRoute.DataTokens = new RouteValueDictionary();
                }

                //look in this namespace to create the controller
                controllerPluginRoute.DataTokens.Add("Namespaces", new[] { controllerType.Namespace });

                //Special case! Check if the controller type implements IRequiresSessionState and if so use our
                //custom webapi session handler
                if (typeof(IRequiresSessionState).IsAssignableFrom(controllerType))
                {
                    controllerPluginRoute.RouteHandler = new SessionHttpControllerRouteHandler();
                }
            }

            //Don't look anywhere else except this namespace!
            controllerPluginRoute.DataTokens.Add("UseNamespaceFallback", false);

            //constraints: only match controllers ending with 'controllerSuffixName' and only match this controller's ID for this route
            if (controllerSuffixName.IsNullOrWhiteSpace() == false)
            {
                controllerPluginRoute.Constraints = new RouteValueDictionary(
                    new Dictionary <string, object>
                {
                    { "controller", @"(\w+)" + controllerSuffixName }
                });
            }

            //match this area
            controllerPluginRoute.DataTokens.Add("area", area.AreaName);
            controllerPluginRoute.DataTokens.Add(Core.Constants.Web.UmbracoDataToken, umbracoTokenValue); //ensure the umbraco token is set

            return(controllerPluginRoute);
        }