/// <summary>
        /// Allows for defining a callback to set the returned <see cref="IPublishedContent"/> for the current request for this route
        /// </summary>
        public static void ForUmbracoPage(
            this ControllerActionEndpointConventionBuilder builder,
            Func <ActionExecutingContext, IPublishedContent> findContent)
        => builder.Add(convention =>
        {
            // filter out matched endpoints that are suppressed
            if (convention.Metadata.OfType <ISuppressMatchingMetadata>().FirstOrDefault()?.SuppressMatching != true)
            {
                // Get the controller action descriptor
                ControllerActionDescriptor?actionDescriptor = convention.Metadata.OfType <ControllerActionDescriptor>().FirstOrDefault();
                if (actionDescriptor != null)
                {
                    // This is more or less like the IApplicationModelProvider, it allows us to add filters, etc... to the ControllerActionDescriptor
                    // dynamically. Here we will add our custom virtual page filter along with a callback in the endpoint's metadata
                    // to execute in order to find the IPublishedContent for the request.

                    var filter = new UmbracoVirtualPageFilterAttribute();

                    // Check if this already contains this filter since we don't want it applied twice.
                    // This could occur if the controller being routed is IVirtualPageController AND
                    // is being routed with ForUmbracoPage. In that case, ForUmbracoPage wins
                    // because the UmbracoVirtualPageFilterAttribute will check for the metadata first since
                    // that is more explicit and flexible in case the same controller is routed multiple times.
                    if (!actionDescriptor.FilterDescriptors.Any(x => x.Filter is UmbracoVirtualPageFilterAttribute))
                    {
                        actionDescriptor.FilterDescriptors.Add(new FilterDescriptor(filter, 0));
                        convention.Metadata.Add(filter);
                    }

                    convention.Metadata.Add(new CustomRouteContentFinderDelegate(findContent));
                }
            }
        });
        public ControllerActionEndpointDataSource(
            IActionDescriptorCollectionProvider actions,
            ActionEndpointFactory endpointFactory,
            OrderedEndpointsSequenceProvider orderSequence)
            : base(actions)
        {
            _endpointFactory = endpointFactory;
            _orderSequence   = orderSequence;
            _routes          = new List <ConventionalRouteEntry>();

            DefaultBuilder = new ControllerActionEndpointConventionBuilder(Lock, Conventions);

            // IMPORTANT: this needs to be the last thing we do in the constructor.
            // Change notifications can happen immediately!
            Subscribe();
        }
示例#3
0
        public ControllerActionEndpointDataSource(
            IActionDescriptorCollectionProvider actions,
            ActionEndpointFactory endpointFactory)
            : base(actions)
        {
            _endpointFactory = endpointFactory;

            _routes = new List <ConventionalRouteEntry>();

            // In traditional conventional routing setup, the routes defined by a user have a order
            // defined by how they are added into the list. We would like to maintain the same order when building
            // up the endpoints too.
            //
            // Start with an order of '1' for conventional routes as attribute routes have a default order of '0'.
            // This is for scenarios dealing with migrating existing Router based code to Endpoint Routing world.
            _order = 1;

            DefaultBuilder = new ControllerActionEndpointConventionBuilder(Lock, Conventions);

            // IMPORTANT: this needs to be the last thing we do in the constructor.
            // Change notifications can happen immediately!
            Subscribe();
        }
示例#4
0
 /// <summary>
 /// 需要Osharp授权
 /// </summary>
 public static ControllerActionEndpointConventionBuilder RequireOsharpAuthorization(this ControllerActionEndpointConventionBuilder builder)
 {
     return(builder.RequireAuthorization(FunctionRequirement.OsharpPolicy));
 }