Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Redirect to old page version while Routing(Initialization)


Hi All, 

I am trying to redirect to older version of same page or different page while routing. But i am getting error in "localhost redirected you too many times."

I want to load previous version of same page or different page when particular page is requsted by the user.


namespace SampleWebsite.web.Business.Initialization
    public class RoutingExtension : IInitializableModule
        private static readonly ILog Logger = LogManager.GetLogger(typeof(RoutingExtension));
        public static Injected ContentVersionRepository { get; set; }

        public void Initialize(InitializationEngine context)
            //Add initialization logic, this method is called once after CMS has been initialized
            Logger.DebugFormat("Routing Initialize start");
            ContentRoute.RoutingContent += ContentRoute_RoutingContent;
            //ContentRoute.RoutedContent += ContentRoute_RoutedContent;
            Logger.DebugFormat("Routing Initialize end");

        private static void ContentRoute_RoutingContent(object sender, RoutingEventArgs e)
                IContentLoader contentLoader = ServiceLocator.Current.GetInstance();
                var urlResolver = ServiceLocator.Current.GetInstance();
                var context = e.RoutingSegmentContext;
                var contentReference = UrlResolver.Current.Route(new UrlBuilder(context.RequestUrl.LocalPath)).ContentLink;

                SitePageData sampleWebsite;
                contentLoader.TryGet(contentReference, out sampleWebsite);
                if (sampleWebsite!= null && sampleWebsite.ExcludeFromMirroring)
                    var list = ContentVersionRepository.Service.List(contentReference);
                    for(int i=list.Count()-1; i>0; i--)
                        var tempContentReference=list.ElementAt(i).ContentLink;
                        contentLoader.TryGet(tempContentReference, out sampleWebsite);
                            Logger.DebugFormat("Routing Item");
            catch (Exception ex)
                Logger.Error("ContentRoute_RoutingContent" + ex.Message.ToString());

        public void Preload(string[] parameters) { }

        public void Uninitialize(InitializationEngine context)
            //Add uninitialization logic



Thanks in Advance.



[Pasting files is not allowed]

Edited, Jun 20, 2017 13:27

Could it be so that once you redirect to previous version of page - next request ends up here as well, meaning that you do next redirect, and next etc.

Just out of curiousity - what's business requirement here?

Jun 24, 2017 7:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.