Esempio n. 1
0
        /// <summary>
        /// This assigns the published content to the request, developers can override this to specify
        /// any other custom attributes required.
        /// </summary>
        /// <param name="pcr"></param>
        /// <param name="filterContext"></param>
        protected virtual void ConfigurePublishedContentRequest(PublishedContentRequest pcr, ActionExecutedContext filterContext)
        {
            if (_contentId.HasValue)
            {
                var content = Umbraco.TypedContent(_contentId);
                if (content == null)
                {
                    throw new InvalidOperationException("Could not resolve content with id " + _contentId);
                }
                pcr.PublishedContent = content;
            }
            else if (_dataTokenName.IsNullOrWhiteSpace() == false)
            {
                var result = filterContext.RouteData.DataTokens[_dataTokenName];
                if (result == null)
                {
                    throw new InvalidOperationException("No data token could be found with the name " + _dataTokenName);
                }
                if ((result is IPublishedContent) == false)
                {
                    throw new InvalidOperationException("The data token resolved with name " + _dataTokenName + " was not an instance of " + typeof(IPublishedContent));
                }
                pcr.PublishedContent = (IPublishedContent)result;
            }

            pcr.Prepare();
        }
        public PublishedContentQuery(IEnumerable <IGraphType> documentGraphTypes)
        {
            Name = "PublishedContentQuery";

            Field <PublishedContentGraphType>()
            .Name("byId")
            .Argument <NonNullGraphType <IdGraphType> >("id", "The unique content id")
            .Resolve(context =>
            {
                var userContext = (UmbracoGraphQLContext)context.UserContext;
                var id          = context.GetArgument <int>("id");
                return(userContext.Umbraco.TypedContent(id));
            });

            Field <PublishedContentGraphType>()
            .Name("byUrl")
            .Argument <NonNullGraphType <StringGraphType> >("url", "The relative content url")
            .Resolve(context =>
            {
                var userContext = (UmbracoGraphQLContext)context.UserContext;
                var url         = context.GetArgument <string>("url");

                var pcr = new PublishedContentRequest(
                    new Uri(userContext.RequestUri, url),
                    userContext.UmbracoContext.RoutingContext,
                    UmbracoConfig.For.UmbracoSettings().WebRouting,
                    null
                    );

                pcr.Prepare();

                if (pcr.IsRedirect || pcr.IsRedirectPermanent || pcr.Is404)
                {
                    return(null);
                }

                return(pcr.PublishedContent);
            });

            Field <NonNullGraphType <PublishedContentAtRootQuery> >()
            .Name("byType")
            .Resolve(context => context.ReturnType)
            .Type(new NonNullGraphType(new PublishedContentByTypeQuery(documentGraphTypes)));

            Field <NonNullGraphType <PublishedContentAtRootQuery> >()
            .Name("atRoot")
            .Resolve(context => context.ReturnType)
            .Type(new NonNullGraphType(new PublishedContentAtRootQuery(documentGraphTypes)));
        }
Esempio n. 3
0
        public ComponentRenderModel(IPublishedContent content = null)
        {
            Content = content != null ? content : new UmbracoHelper(UmbracoContext.Current).TypedContentAtRoot().FirstOrDefault();

            var baseUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.Request.Path, "/");
            var umbUrl  = baseUrl + Content.Url.TrimStart('/');

            var pcr = new PublishedContentRequest(
                new Uri(umbUrl),
                UmbracoContext.Current.RoutingContext,
                UmbracoConfig.For.UmbracoSettings().WebRouting,
                s => Roles.Provider.GetRolesForUser(s)
                );

            UmbracoContext.Current.PublishedContentRequest = pcr;
            UmbracoContext.Current.PublishedContentRequest.PublishedContent = Content;

            pcr.Prepare();
        }
Esempio n. 4
0
        /// <summary>
        /// Processses the Umbraco Request
        /// </summary>
        /// <param name="httpContext"></param>
        void ProcessRequest(HttpContextBase httpContext)
        {
            // do not process if client-side request
            if (httpContext.Request.Url.IsClientSideRequest())
            {
                return;
            }

            if (UmbracoContext.Current == null)
            {
                throw new InvalidOperationException("The UmbracoContext.Current is null, ProcessRequest cannot proceed unless there is a current UmbracoContext");
            }
            if (UmbracoContext.Current.RoutingContext == null)
            {
                throw new InvalidOperationException("The UmbracoContext.RoutingContext has not been assigned, ProcessRequest cannot proceed unless there is a RoutingContext assigned to the UmbracoContext");
            }

            var umbracoContext = UmbracoContext.Current;

            // do not process but remap to handler if it is a base rest request
            if (BaseRest.BaseRestHandler.IsBaseRestRequest(umbracoContext.OriginalRequestUrl))
            {
                httpContext.RemapHandler(new BaseRest.BaseRestHandler());
                return;
            }

            // do not process if this request is not a front-end routable page
            var isRoutableAttempt = EnsureUmbracoRoutablePage(umbracoContext, httpContext);

            //raise event here
            OnRouteAttempt(new RoutableAttemptEventArgs(isRoutableAttempt.Result, umbracoContext, httpContext));
            if (!isRoutableAttempt.Success)
            {
                return;
            }


            httpContext.Trace.Write("UmbracoModule", "Umbraco request confirmed");

            // ok, process

            // note: requestModule.UmbracoRewrite also did some stripping of &umbPage
            // from the querystring... that was in v3.x to fix some issues with pre-forms
            // auth. Paul Sterling confirmed in jan. 2013 that we can get rid of it.

            // instanciate, prepare and process the published content request
            // important to use CleanedUmbracoUrl - lowercase path-only version of the current url
            var pcr = new PublishedContentRequest(umbracoContext.CleanedUmbracoUrl, umbracoContext.RoutingContext);

            umbracoContext.PublishedContentRequest = pcr;
            pcr.Prepare();

            // HandleHttpResponseStatus returns a value indicating that the request should
            // not be processed any further, eg because it has been redirect. then, exit.
            if (HandleHttpResponseStatus(httpContext, pcr))
            {
                return;
            }

            if (!pcr.HasPublishedContent)
            {
                httpContext.RemapHandler(new PublishedContentNotFoundHandler());
            }
            else
            {
                RewriteToUmbracoHandler(httpContext, pcr);
            }
        }
 protected virtual void PreparePublishedContentRequest(PublishedContentRequest publishedContentRequest)
 {
     publishedContentRequest.Prepare();
 }