Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Ha Bui
Oct 1, 2019
  3133
(3 votes)

Get rid of EPiServer Commerce Migrate redirect loop

Phew! Take 2 hours to get rids of the infinitive loop from EPiServer ECommerce after upgrade from 9.2 to 12.17!

You can Google search with: episerver commerce migration loop

Then some guys below appear:

1. https://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2019/5/passing-thru-episervercommercemigrate-when-created-new-site-in-azure/

2. https://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2016/10/too-many-redirects-error-in-the-browser-after-package-update/

Some good instructions but does not work for my case: MigrateRedirect -> <RequireLogin> -> Owin -> MigrateRedirect -> <RequireLogin> -> ...

You can see more in those class:

EPiServer.Commerce.Internal.Migration.MigrationInitializationModule

EPiServer.Commerce.Internal.Migration.MigrationManager

...

Okay, so how can we resolve this? Some angeles below will help:

1.  // EPiServer.Commerce.Internal.Migration.MigrationManager

public virtual void MigrateAsync()

2. IoC with StructureMap and Interceptors holy light

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
[ModuleDependency(typeof(CmsCoreInitialization))]
internal class ContainerInitialization : IConfigurableModule, IInitializableModule

and

public void ConfigureContainer(ServiceConfigurationContext context)
{
    ...
    context.ConfigurationComplete += (o, e) =>
            {
                e.Services.Intercept<MigrationManager>((locator, defaultMigrationManager) =>
                    new MigrationManagerInterceptor(defaultMigrationManager
                            , locator.GetInstance<MigrationStore>()
                            , locator.GetInstance<MigrateActionUrlResolver>()));
            };
}

and last one:

public class MigrationManagerInterceptor : MigrationManager
    {
        private MigrationManager _defaultMigrationManager;

        public MigrationManagerInterceptor(
            MigrationManager defaultMigrationManager
            , MigrationStore migrationStore
            , MigrateActionUrlResolver migrateActionUrlResolver)
            : base(migrationStore, migrateActionUrlResolver)
        {
            _defaultMigrationManager = defaultMigrationManager;
        }

        public override void RedirectToMigrationView()
        {
            MigrateAsync();
            return;
        }
    }

Good bye redirect loop! Cheer!

// Ha Bui

Oct 01, 2019

Comments

Luc Gosso (MVP)
Luc Gosso (MVP) Oct 1, 2019 07:37 AM

Thank you for sharing, ive been struggling with this for years! 

Your solution is probably the best in history... 

My work arounds was "Log in as webadmin" before you release - not always possible

Or change in Appsetting: AutoMigrateEPiServer set to true use to work - but i know, not always applicable

Ha Bui
Ha Bui Oct 2, 2019 08:00 AM

Thank @GOSSO for your very constructive comment! I also tried some solutions as your but issue still there (sometime it works, weird)

Thank @Quan for your recap / overview solution! I also agree with you about documentation that should be better because of upgrading is very high risky, if we have not then how can motivate partner / customer upgrade to newer version?

// Ha Bui

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog