Redirect Repository that handles CRUD operations for the repository collection Utilizes Umbraco Database context to persist redirects into the database but utilizes an in-memory collection for fast querying.
        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);
        }
        public DeleteRedirectResponse Delete(int id)
        {
            if (id == 0)
            {
                return new DeleteRedirectResponse()
                       {
                           Success = false, Message = "Invalid ID passed for redirect to delete"
                       }
            }
            ;

            try
            {
                RedirectRepository.DeleteRedirect(id);

                return(new DeleteRedirectResponse()
                {
                    Success = true
                });
            }
            catch (Exception e)
            {
                return(new DeleteRedirectResponse()
                {
                    Success = false, Message = "There was an error deleting the redirect : " + e.Message
                });
            }
        }
    }
        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);
        }
Beispiel #4
0
 /// <summary>
 /// Hack to support legacy version checking. This supports the state that exists before
 /// we implemented migration version entry on database create, which will exist moving forward.
 /// This only supports legacy installs
 /// </summary>
 /// <param name="db">Database</param>
 /// <param name="migrationService">Migration service</param>
 /// <returns>True if success</returns>
 private bool ValidateTableRead(UmbracoDatabase db, IMigrationEntryService migrationService)
 {
     try
     {
         // run through creating and deleting a redirect.
         var redirect = RedirectRepository.AddRedirect(true, "old", "new", "notes");
         RedirectRepository.DeleteRedirect(redirect.Id);
         this.AddTargetVersionMigrationEntry(migrationService);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        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);
        }
Beispiel #6
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);
        }
        public UpdateRedirectResponse Update(UpdateRedirectRequest request)
        {
            if (request == null)
            {
                return new UpdateRedirectResponse()
                       {
                           Success = false, Message = "Request was empty"
                       }
            }
            ;
            if (!ModelState.IsValid)
            {
                return new UpdateRedirectResponse()
                       {
                           Success = false, Message = "Missing required attributes"
                       }
            }
            ;

            try
            {
                var redirect = RedirectRepository.UpdateRedirect(request.Redirect);

                return(new UpdateRedirectResponse()
                {
                    Success = true, UpdatedRedirect = redirect
                });
            }
            catch (Exception e)
            {
                return(new UpdateRedirectResponse()
                {
                    Success = false, Message = "There was an error updating the redirect : " + e.Message
                });
            }
        }
        public AddRedirectResponse Add(AddRedirectRequest request)
        {
            if (request == null)
            {
                return new AddRedirectResponse()
                       {
                           Success = false, Message = "Request was empty"
                       }
            }
            ;
            if (!ModelState.IsValid)
            {
                return new AddRedirectResponse()
                       {
                           Success = false, Message = "Missing required attributes"
                       }
            }
            ;

            try
            {
                var redirect = RedirectRepository.AddRedirect(request.OldUrl, request.NewUrl, request.Notes);

                return(new AddRedirectResponse()
                {
                    Success = true, NewRedirect = redirect
                });
            }
            catch (Exception e)
            {
                return(new AddRedirectResponse()
                {
                    Success = false, Message = "There was an error adding the redirect : " + e.Message
                });
            }
        }
 public IEnumerable <Redirect> GetAll()
 {
     return(RedirectRepository.GetAllRedirects());
 }
Beispiel #10
0
 public void ClearCache()
 {
     RedirectRepository.ClearCache();
 }