valdisiljuconoks / localization-provider-opti

Database driven localization provider for Optimizely (ex. Episerver) websites
Apache License 2.0
11 stars 17 forks source link

Cannot use Localization ui in Optimizely, 404 on RootUrl #187

Closed robin-de-gier closed 1 year ago

robin-de-gier commented 1 year ago

I cannot seem to get the ui to work. Currently working on updating our EPiServer to v12 which means we also had to update this library and we're aiming for the newest version. However the Localization ui does not load and according to the dev console it is a 404 on the RootUrl (so localhost:5000/localization-admin on default).

Screenshot 2022-12-13 at 13 40 18

We copied our DbLocalization settings to the Alloy project to test if some other settings were conflicting, but I cannot get it to work with the Alloy project either.

This is the Startup.cs we use in the Alloy project:

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())
        {
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(_webHostingEnvironment.ContentRootPath, "App_Data"));

            services.Configure<SchedulerOptions>(options => options.Enabled = false);
        }

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

        services
            .Configure<RequestLocalizationOptions>(opts =>
            {
                var supportedCultures = new List<CultureInfo>
                {
                    new("nl"),
                    new("en")
                };

                opts.DefaultRequestCulture = new RequestCulture("nl");
                opts.SupportedCultures = supportedCultures;
                opts.SupportedUICultures = supportedCultures;
            })
            .AddDbLocalizationProvider(ctx => { ctx.UseSqlServer(_configuration.GetConnectionString("EPiServerDB")); })
            .AddOptimizely();

        services
            .AddDbLocalizationProviderAdminUI(setup =>
            {
                setup.AccessPolicyOptions = builder => builder.AddRequirements(new DenyAnonymousAuthorizationRequirement());
            })
            .AddOptimizelyAdminUI();

        // Required by Wangkanai.Detection
        services.AddDetection();

        services.AddSession(options =>
        {
            options.IdleTimeout = TimeSpan.FromSeconds(10);
            options.Cookie.HttpOnly = true;
            options.Cookie.IsEssential = true;
        });
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        // Required by Wangkanai.Detection
        app.UseDetection();
        app.UseSession();

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

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

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

For the Alloy project I have the following packages:

<ItemGroup>
    <PackageReference Include="EPiServer.CMS" Version="12.15.0"/>
    <PackageReference Include="EPiServer.CMS.AspNetCore" Version="12.11.0"/>
    <PackageReference Include="EPiServer.Framework" Version="12.11.0"/>
    <PackageReference Include="EPiServer.Hosting" Version="12.11.0"/>
    <PackageReference Include="Wangkanai.Detection" Version="5.2.0"/>
    <PackageReference Include="DbLocalizationProvider.AdminUI.EPiServer" Version="7.5.0"/>
    <PackageReference Include="DbLocalizationProvider.EPiServer" Version="7.5.0"/>
    <PackageReference Include="LocalizationProvider.Storage.SqlServer" Version="7.5.0"/>
</ItemGroup>

I can't find any settings I might have missed in the documentation. Features like @Html.GetTranslations and @Html.Translate work as expected, so only the retrieval of the localization ui seems to be the problem.

valdisiljuconoks commented 1 year ago

Hi,

I think you might be missing endpoints.MapRazorPages();

Check sample setup code from sandbox: https://github.com/valdisiljuconoks/localization-provider-epi/blob/main/docs/getting-started-epi.md#adding-provider-adminui-to-the-application

robin-de-gier commented 1 year ago

Thankyou! Missed that line and I have been pulling my hair for a while now. Thanks for the quick reply and the solution.