FindRedirect() public static method

Handles finding a redirect based on the oldUrl
public static FindRedirect ( string oldUrl ) : Redirect
oldUrl string Url to search for
return Simple301.Core.Models.Redirect
        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);
        }
Esempio n. 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)
            {
                return(false);
            }

            //Found one, set the 301 redirect on the request and return
            request.SetRedirectPermanent(matchedRedirect.NewUrl);
            return(true);
        }
Esempio n. 3
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);
        }