valdisiljuconoks / localization-provider-core

Database driven localization provider for .NET applications (with administrative management UI)
Apache License 2.0
118 stars 22 forks source link

Resources not loading in Optimizely 12.19 project #120

Closed johnligt closed 1 year ago

johnligt commented 1 year ago

Hello Valdis,

I'm working on an upgrade of an Episerver 11 site. I've started with an empty Optimizely 12 project, attached to an upgraded version of the old database, and importing the various elements of the site one by one.

Somehow the content of the DbLocalization admin pages are not loading. In the console I see a 404 for /localization-admin The text in the button which should open the admin pages is "DbLocalizationProvider.AdminUI.EPiServer.EPiServerResources.MenuTitle"

I'm using IIS Express, with Optimizely 12.19 and DbLocalization 7.5.1

Do you have any suggestions on what I'm doing wrong? I've added the contents of my startup.cs below.

Best regards,

John

===============================================================

` public class Startup { private readonly IWebHostEnvironment _webHostingEnvironment; private readonly IConfiguration _configuration;

    public Startup(IWebHostEnvironment webHostingEnvironment, IConfiguration configuration)
    {
        _webHostingEnvironment = webHostingEnvironment;
        _configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        if (_webHostingEnvironment.IsDevelopment())
        {
            //Add development configuration
            services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IFirstRequestInitializer), typeof(UsersInstaller)));
        }

        services.AddDbContext<ApplicationDbContext<ApplicationUser>>(
            options => options.UseSqlServer(_configuration.GetConnectionString("EPiServerDB")));

        services.AddMvc()
                .AddRazorOptions(ro => ro.ViewLocationExpanders.Add(new FeatureViewLocationExpander()));

        services.AddCms()
            .AddCmsAspNetIdentity<ApplicationUser>();

        services.AddMemoryCache().AddAuthorization();

        var supportedCultures = new List<CultureInfo> { new CultureInfo("nl"), new CultureInfo("en") };

        services.Configure<RequestLocalizationOptions>(opts =>
        {
            opts.DefaultRequestCulture = new RequestCulture("nl");
            opts.SupportedCultures = supportedCultures;
            opts.SupportedUICultures = supportedCultures;
        });

        services.AddDbLocalizationProvider(ctx =>
        {
            ctx.EnableInvariantCultureFallback = true;
            ctx.ScanAllAssemblies = true;
            ctx.FallbackLanguages.Try(supportedCultures);
            ctx.UseSqlServer(_configuration.GetConnectionString("EPiServerDB"));               
        });

        services.AddDbLocalizationProviderAdminUI()
        .AddOptimizelyAdminUI();  // add Optimizely integration (adds menu items and stuff)

        services.AddRouting();

        services.ConfigureApplicationCookie(options =>
        {
            options.LoginPath = "/util/Login";
        });

        services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IFirstRequestInitializer), typeof(UsersInstaller)));
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();

        app.UseDbLocalizationProvider();
        app.UseDbLocalizationProviderAdminUI();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapContent();                           
        });
    }
}

`

valdisiljuconoks commented 1 year ago

I think you are also missing "AddOptimizely();" when adding localization provider.

You can try to compare sample app setup with yours and see what you might be missing..

https://github.com/valdisiljuconoks/localization-provider-epi/blob/main/samples/AlloySampleSite/Startup.cs

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: John Ligtenberg @.> Sent: Tuesday, May 9, 2023 6:19:29 PM To: valdisiljuconoks/localization-provider-core @.> Cc: Subscribed @.***> Subject: [valdisiljuconoks/localization-provider-core] Resources not loading in Optimizely 12.19 project (Issue #120)

Hello Valdis,

I'm working on an upgrade of an Episerver 11 site. I've started with an empty Optimizely 12 project, attached to an upgraded version of the old database, and importing the various elements of the site one by one.

Somehow the content of the DbLocalization admin pages are not loading. In the console I see a 404 for /localization-admin The text in the button which should open the admin pages is "DbLocalizationProvider.AdminUI.EPiServer.EPiServerResources.MenuTitle"

I'm using IIS Express, with Optimizely 12.19 and DbLocalization 7.5.1

Do you have any suggestions on what I'm doing wrong? I've added the contents of my startup.cs below.

Best regards,

John

===============================================================

` public class Startup { private readonly IWebHostEnvironment _webHostingEnvironment; private readonly IConfiguration _configuration;

public Startup(IWebHostEnvironment webHostingEnvironment, IConfiguration configuration)
{
    _webHostingEnvironment = webHostingEnvironment;
    _configuration = configuration;
}

public void ConfigureServices(IServiceCollection services)
{
    if (_webHostingEnvironment.IsDevelopment())
    {
        //Add development configuration
        services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IFirstRequestInitializer), typeof(UsersInstaller)));
    }

    services.AddDbContext<ApplicationDbContext<ApplicationUser>>(
        options => options.UseSqlServer(_configuration.GetConnectionString("EPiServerDB")));

    services.AddMvc()
            .AddRazorOptions(ro => ro.ViewLocationExpanders.Add(new FeatureViewLocationExpander()));

    services.AddCms()
        .AddCmsAspNetIdentity<ApplicationUser>();

    services.AddMemoryCache().AddAuthorization();

    var supportedCultures = new List<CultureInfo> { new CultureInfo("nl"), new CultureInfo("en") };

    services.Configure<RequestLocalizationOptions>(opts =>
    {
        opts.DefaultRequestCulture = new RequestCulture("nl");
        opts.SupportedCultures = supportedCultures;
        opts.SupportedUICultures = supportedCultures;
    });

    services.AddDbLocalizationProvider(ctx =>
    {
        ctx.EnableInvariantCultureFallback = true;
        ctx.ScanAllAssemblies = true;
        ctx.FallbackLanguages.Try(supportedCultures);
        ctx.UseSqlServer(_configuration.GetConnectionString("EPiServerDB"));
    });

    services.AddDbLocalizationProviderAdminUI()
    .AddOptimizelyAdminUI();  // add Optimizely integration (adds menu items and stuff)

    services.AddRouting();

    services.ConfigureApplicationCookie(options =>
    {
        options.LoginPath = "/util/Login";
    });

    services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IFirstRequestInitializer), typeof(UsersInstaller)));
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseStaticFiles();
    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();

    app.UseDbLocalizationProvider();
    app.UseDbLocalizationProviderAdminUI();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapContent();
    });
}

}

`

— Reply to this email directly, view it on GitHubhttps://github.com/valdisiljuconoks/localization-provider-core/issues/120, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AANPOCYII7XIFBJ37JWD6JLXFJOADANCNFSM6AAAAAAX3OQ3AM. You are receiving this because you are subscribed to this thread.Message ID: @.***>

johnligt commented 1 year ago

Hello Valdis,

Thanks, I was indeed missing AddOptimizely();

I also needed to add endpoints.MapRazorPages();

After that the resource editor buttons loaded, but not the localizations.

Somehow under "Settings" the languages are not loaded, and in the console I see a 404 on https://localcore.lumc.nl:8091/localization-admin/api/service/get

valdisiljuconoks commented 1 year ago

startup file looks the same as in sample app?

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: John Ligtenberg @.> Sent: Wednesday, May 10, 2023 12:05:02 AM To: valdisiljuconoks/localization-provider-core @.> Cc: valdis iljuconoks @.>; Comment @.> Subject: Re: [valdisiljuconoks/localization-provider-core] Resources not loading in Optimizely 12.19 project (Issue #120)

Hello Valdis,

Thanks, I was indeed missing AddOptimizely();

I also needed to add endpoints.MapRazorPages();

After that the resource editor buttons loaded, but not the localizations.

Somehow under "Settings" the languages are not loaded, and in the console I see a 404 on https://localcore.lumc.nl:8091/localization-admin/api/service/get

— Reply to this email directly, view it on GitHubhttps://github.com/valdisiljuconoks/localization-provider-core/issues/120#issuecomment-1540888821, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AANPOCYLW7CKWVR43VVDSQ3XFKWP5ANCNFSM6AAAAAAX3OQ3AM. You are receiving this because you commented.Message ID: @.***>

johnligt commented 1 year ago

Hi Valdis,

Things started working after I added endpoints.MapControllerRoute("Register", "/Register", new { controller = "Register", action = "Index" });

I had no idea this was necessary for the DbLocalization admin page.

Thank you very much for your help!

Best regards,

John

valdisiljuconoks commented 1 year ago

It's super weird and no, this route is not needed for the localization provider to work.. weird indeed.

johnligt commented 1 year ago

Indeed. I have just tried commenting and de-commenting this one single line, and it makes the difference between not-loading and loading the localization resources, with the corresponding 404 on /localization-admin/api/service/get So it is certainly reproducible (in my environment). But there must be something else going on.

valdisiljuconoks commented 1 year ago

Out of curiosity, if replace "Register" route with for example default one, same effect?

endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");


From: John Ligtenberg @.> Sent: Thursday, May 11, 2023 09:48 To: valdisiljuconoks/localization-provider-core @.> Cc: valdis iljuconoks @.>; State change @.> Subject: Re: [valdisiljuconoks/localization-provider-core] Resources not loading in Optimizely 12.19 project (Issue #120)

Indeed. I have just tried commenting and de-commenting this one single line, and it makes the difference between not-loading and loading the localization resources, with the corresponding 404 on /localization-admin/api/service/get So it is certainly reproducible (in my environment). But there must be something else going on.

— Reply to this email directly, view it on GitHubhttps://github.com/valdisiljuconoks/localization-provider-core/issues/120#issuecomment-1543428400, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AANPOC3ILSH5SOWAV4LDEHDXFSDSRANCNFSM6AAAAAAX3OQ3AM. You are receiving this because you modified the open/close state.Message ID: @.***>

johnligt commented 1 year ago

Yes, it has the same effect. And so has endpoints.MapControllerRoute("TestView", "/TestView", new { controller = "Test", action = "TestView" });

But when no endpoints.MapControllerRoute is present, I get the 404 on /localization-admin/api/service/get and the resources do not load.