コード例 #1
0
        public bool TryFindContent(PublishedContentRequest request)
        {
            //Get the requested URL path + query
            var path     = request.Uri.PathAndQuery.ToLower();
            var fullpath = request.Uri.OriginalString.ToLower();

            //Check the table
            var redirectLookupTable = RedirectRepository.GetLookupTable();

            Redirect matchedRedirect;

            if (redirectLookupTable.TryGetValue(path, out matchedRedirect))
            {
                // set the 301 redirect on the request and return
                request.SetRedirectPermanent(matchedRedirect.NewUrl);
                return(true);
            }

            if (redirectLookupTable.TryGetValue(fullpath, out matchedRedirect))
            {
                // set the 301 redirect on the request and return
                request.SetRedirectPermanent(matchedRedirect.NewUrl);
                return(true);
            }


            //did not found one
            return(false);
        }
コード例 #2
0
        public bool TryFindContent(PublishedContentRequest request)
        {
            //Get the requested URL path + query
            var path = request.Uri.PathAndQuery.ToLower();

            //Check the table
            var matchedRedirect = RedirectRepository.FindRedirect(path);

            if (matchedRedirect == null || string.IsNullOrWhiteSpace(matchedRedirect.NewUrl))
            {
                return(false);
            }

            //Found one, set the 301 redirect on the request and return
            var redirectUri = GetRoute(matchedRedirect.NewUrl);

            if (redirectUri.IsAbsoluteUri)
            {
                //if is absolute then redirect using the host
                request.SetRedirectPermanent(redirectUri.AbsoluteUri);
            }
            else
            {
                //redirect is relative, so continue as before
                request.SetRedirectPermanent(matchedRedirect.NewUrl);
            }

            return(true);
        }
コード例 #3
0
        public bool TryFindContent(PublishedContentRequest request)
        {
            //Get the requested URL path + query
            var path = request.Uri.PathAndQuery.ToLower();

            //Check the table
            var matchedRedirect = RedirectRepository.FindRedirect(path);

            if (matchedRedirect == null)
            {
                return(false);
            }

            //Found one, set the 301 redirect on the request and return
            request.SetRedirectPermanent(matchedRedirect.NewUrl);
            return(true);
        }
コード例 #4
0
        public bool TryFindContent(PublishedContentRequest contentRequest)
        {
            // read in the path from the PublishedContentRequest
            var path = contentRequest.Uri.AbsolutePath;

            // find any published item with a formerUrl matching the path
            var umbracoHelper   = new UmbracoHelper(UmbracoContext.Current);
            var matchingContent = umbracoHelper.TypedContentSingleAtXPath("//TextPage[formerUrl/text() = '" + path + "']");

            if (matchingContent == null)
            {
                // return false, there is no matching content
                return(false);
            }

            //contentRequest.PublishedContent = matchingContent;
            contentRequest.SetRedirectPermanent(matchingContent.Url);
            return(true);
        }
コード例 #5
0
        public bool TryFindContent(PublishedContentRequest request)
        {
            //Get the requested URL path + query (url decode to handle e.g. chinese)
            var path = HttpUtility.UrlDecode(request.Uri.PathAndQuery.ToLower());

            _log.Debug($"Trying to find redirect: {path}");

            //Check the table
            var matchedRedirect = RedirectRepository.FindRedirect(path);

            if (matchedRedirect == null)
            {
                return(false);
            }

            //Found one, set the 301 redirect on the request and return
            request.SetRedirectPermanent(matchedRedirect.NewUrl);
            return(true);
        }
コード例 #6
0
        public override bool TryFindContent(PublishedContentRequest contentRequest)
        {
            // eg / or /path/to/whatever
            var url = contentRequest.Uri.GetAbsolutePathDecoded();

            var mdRoot = "/" + MarkdownLogic.BaseUrl;

            if (url.StartsWith("/projects/umbraco-pro/contour/documentation"))
            {
                mdRoot = "/projects";
            }

            // ensure it's a md url
            if (url.StartsWith(mdRoot) == false)
            {
                return(false); // not for us
            }
            // find the root content
            var node = FindContent(contentRequest, mdRoot);

            if (node == null)
            {
                return(false);
            }

            // kill those old urls
            foreach (var s in new [] { "master", "v480" })
            {
                if (url.StartsWith(mdRoot + "/" + s))
                {
                    url = url.Replace(mdRoot + "/" + s, mdRoot);
                    contentRequest.SetRedirectPermanent(url);
                    return(true);
                }
            }

            // find the md file
            var mdFilepath = FindMarkdownFile(url);

            //return the broken link doc page
            var is404 = false;

            if (mdFilepath == null)
            {
                mdFilepath = FindMarkdownFile("/documentation/broken-link");
                is404      = true;
            }
            if (mdFilepath == null)
            {
                // clear the published content (that was set by FindContent) to cause a 404, and in
                // both case return 'true' because there's no point other finders try to handle the request
                contentRequest.PublishedContent = null;
                return(true);
            }

            if (is404)
            {
                contentRequest.SetIs404();
            }

            // set the context vars
            var httpContext = contentRequest.RoutingContext.UmbracoContext.HttpContext;

            httpContext.Items[MarkdownLogic.MarkdownPathKey] = mdFilepath;
            httpContext.Items["topicTitle"] = string.Join(" - ", httpContext.Request.RawUrl
                                                          .Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
                                                          .Skip(1)
                                                          .Reverse());

            // override the template
            const string altTemplate   = "DocumentationSubpage";
            var          templateIsSet = contentRequest.TrySetTemplate(altTemplate);

            //httpContext.Trace.Write("Markdown Files Handler",
            //    string.Format("Template changed to: '{0}' is {1}", altTemplate, templateIsSet));

            // be happy
            return(true);
        }
コード例 #7
0
        /// <inheritdoc/>
        public bool TryFindContent(PublishedContentRequest contentRequest)
        {
            if (!contentRequest.Is404)
            {
                // TODO: use contentRequest.Uri?
                string url    = HttpContext.Current.Request.Url.ToString();
                string domain = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);

                try
                {
                    Tuple <IPublishedContent, int> result;
                    IPublishedContent rerouteContent = null;
                    int statusCode = 0;

                    // Check the cache first
                    object cached = UrlRewriteCache.GetItem(url);
                    if (cached != null)
                    {
                        result         = (Tuple <IPublishedContent, int>)cached;
                        rerouteContent = result.Item1;
                        statusCode     = result.Item2;
                    }
                    else
                    {
                        // Nothing in the cache so let's taverse through each level of the site until we find it.
                        IPublishedContent root = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetAtRoot()
                                                 .FirstOrDefault(p => p.UrlAbsolute().StartsWith(domain));

                        // Start looking for a match, this is recursive.
                        result = this.TryFindRewriteNode(root, BloodhoundPropertyEditor.PropertyEditorAlias, url);

                        if (result != null)
                        {
                            rerouteContent = result.Item1;
                            statusCode     = result.Item2;
                        }
                    }

                    // We have a result!
                    if (statusCode > 0 && rerouteContent != null)
                    {
                        if (statusCode == 301)
                        {
                            contentRequest.SetRedirectPermanent(rerouteContent.Url);
                        }
                        else
                        {
                            // 302
                            contentRequest.SetRedirect(rerouteContent.Url);
                        }

                        contentRequest.PublishedContent = rerouteContent;
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error <BloodhoundApplicationEvents>($"An error occured attempting to provide a rewrite for the following request {url}", ex);
                }
            }

            return(contentRequest.PublishedContent != null);
        }