示例#1
0
        /// <inheritdoc />
        /// <summary>
        /// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
        /// </summary>
        /// <param name="contentRequest">The <c>PublishedContentRequest</c>.</param>
        /// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
        /// <remarks>Optionally, can also assign the template or anything else on the document request, although that is not required.</remarks>
        public bool TryFindContent(PublishedContentRequest contentRequest)
        {
            if (contentRequest.PublishedContent == null)
            {
                IPublishedContent home = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetAtRoot().First();

                IPublishedContent notFoundNode = home.Children.Single(x => x.Name == "Error-404");

                contentRequest.SetResponseStatus(404, "404 Page Not Found");

                contentRequest.PublishedContent = notFoundNode;
            }

            return(contentRequest.PublishedContent != null);
        }
示例#2
0
        public bool TryFindContent(PublishedContentRequest contentRequest)
        {
            if (!contentRequest.Is404)
            {
                return(contentRequest.PublishedContent != null);
            }

            var errorPageService           = DependencyResolver.Current.GetService <IErrorPageService>();
            IPublishedContent notFoundNode = errorPageService.GetErrorPage();

            contentRequest.SetResponseStatus(404, "404 Page Not Found");
            contentRequest.PublishedContent = notFoundNode;

            return(contentRequest.PublishedContent != null);
        }
        public bool TryFindContent(PublishedContentRequest contentRequest)
        {
            //Check request is a 404
            if (contentRequest.Is404)
            {
                //Get the home node
                var home = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetAtRoot().Single(x => x.DocumentTypeAlias == "CWS-Home");

                //Get the 404 node
                var notFoundNode = home.Children.Single(x => x.DocumentTypeAlias == "CWS-404");

                //Set Response Status to be HTTP 404
                contentRequest.SetResponseStatus(404, "404 Page Not Found");

                //Set the node to be the not found node
                contentRequest.PublishedContent = notFoundNode;
            }

            //Not sure about this line - copied from Lee K's GIST
            //https://gist.github.com/leekelleher/5966488
            return(contentRequest.PublishedContent != null);
        }
示例#4
0
        public bool TryFindContent(PublishedContentRequest contentRequest)
        {
            if (!contentRequest.Is404)
            {
                return(contentRequest.PublishedContent != null);
            }

            contentRequest.SetResponseStatus(404, "404 Page Not Found");
            IPublishedContent error404 = null;

            // Set the Error404 error published page
            int homeId = ContentHelper.Instance.GetHomeId();

            if (homeId > 0)
            {
                IPublishedContent homeContent = ContentHelper.Instance.UmbracoHelper.TypedContent(homeId);
                error404 = homeContent.Children.FirstOrDefault(p => p.DocumentTypeAlias.InvariantEquals("Error404"));
                contentRequest.PublishedContent = error404;
            }

            return(contentRequest.PublishedContent != null);
        }