November Happy Hour will be moved to Thursday December 5th.

Setting up content editing for an externally hosted frontend breaks images in edit mode.

Vote:
 

If you configure the CMS to use an external frontend site (to enable on-page editing on the externa site), images will break at some places in edit mode. Thumbnail images for example.

Configuration:

services.ConfigureForExternalTemplates();
services.Configure<ExternalApplicationOptions>(options => options.OptimizeForDelivery = true);

Thumbnail images will get this url

https://my-frontend-host.com/EPiServer/CMS/Content/globalassets/test-assets/hero.jpg,,62/Thumbnail?epieditmode=False?1695142172388

my-fronend-host.com is the frontend site, not the CMS site.

I have tried to set the CMS-hostname to type "Edit", but that didn't help.

Is this a bug, or did I configure something wrong?

#308707
Sep 19, 2023 17:10
Vote:
 

How to reproduce

  • Set up a new cms by doing dotnet new epi-alloy-mvc
  • Update to latest version of Episerver.CMS (12.22.8)
  • Add latest version of EPiServer.ContentDeliveryAPI.CMS (3.9.0)
    and configure Delivery API like this:
     services.AddContentDeliveryApi(options =>
     {
     }).WithFriendlyUrl();
     services.Configure<EPiServer.ContentApi.Core.Configuration.ContentApiOptions>(options =>
     {
         options.IncludeEmptyContentProperties = false;
         options.IncludeMasterLanguage = false;
     });
  • Configure edtiting on external site like this
      services.ConfigureForExternalTemplates();
      services.Configure<ExternalApplicationOptions>(options => options.OptimizeForDelivery = true);
  • Add a new host under Manage Websites in admin mode
    Host name: my-frontend-host.com
    Type: Primary

Errors

1. ForceAbsolute option for ContentDelivery API will have no effect on the json returned from the API. Host name is always included.
2. Thumbnail images are broken in edit mode, since they are requested using the frontend host name (but with the port of the CMS host)

#309840
Oct 02, 2023 14:50
Vote:
 

When decompiling the method seems it does the following

 public void ConfigureForExternalTemplates()
        {
            ServiceLocator.Current.GetInstance<RoutingOptions>().UsePrimaryHostForOutgoingUrls = true;
            RegisterFakeTemplate = true;
        }

Based on that code seems to be doing what you are describing.  Not sure why you would ever use primary host for images though.

#309841
Oct 02, 2023 15:06
Erik Henningson - Oct 03, 2023 7:35
Thanks Mark! Maybe I should try to not call ConfigureForExternalTemplates, but just RegisterFakeTemplate, and see if that works 😊
Erik Henningson - Oct 04, 2023 6:53
Nah, that didn't help.
I tried
services.Configure(delegate (TemplateOptions r)
{
r.RegisterFakeTemplate = true;
});
services.Configure(delegate (ContentApiOptions options)
{
options.ValidateTemplateForContentUrl = false;
});
instead of
services.ConfigureForExternalTemplates();
It fixes the issue with thumbnails, but it it doesn't load the external site when trying to do on-page editing.
Vote:
 

Did you find a solution to this? I'm facing the same issue.

#320968
Apr 24, 2024 11:23
Vote:
 

Yes. This issue has "un-officially" been confirmed as a bug, but will most likely not be fixed until next major release. With the help from Optimizely I added this Initialization module. It adds an event that fixes the hostname for images, both in edit mode, and in the Content Delivery API.

[ModuleDependency(typeof(InitializationModule))]
public class MediaUrlGeneratorInitialization : IConfigurableModule
{
    private IContentUrlGeneratorEvents _contentUrlGeneratorEvents = null!;
    private IContentLoader _contentLoader = null!;

    public void ConfigureContainer(ServiceConfigurationContext context)
    {
    }

    public void Initialize(InitializationEngine context)
    {
        _contentLoader = context.Locate.Advanced.GetInstance<IContentLoader>();
        _contentUrlGeneratorEvents = context.Locate.Advanced.GetInstance<IContentUrlGeneratorEvents>();
        _contentUrlGeneratorEvents.GeneratedUrl += ContentUrlGeneratorEvents_GeneratedUrl;
    }

    public void Uninitialize(InitializationEngine context)
    {
        _contentUrlGeneratorEvents.GeneratedUrl -= ContentUrlGeneratorEvents_GeneratedUrl;
    }

    private void ContentUrlGeneratorEvents_GeneratedUrl(object? sender, UrlGeneratorEventArgs args)
    {
        if (args.Context.Host is null)
        {
            return;
        }

        if (args.Context.Url.IsPathRelative)
        {
            return;
        }

        var hosts = args.Context.Host.Site?.Hosts;
        var editHost = hosts.FirstOfType(HostDefinitionType.Edit);
        if (editHost is null)
        {
            return;
        }

        var contentLink = args.Context.ContentLink;
        if (ContentReference.IsNullOrEmpty(contentLink))
        {
            return;
        }

        var content = _contentLoader.Get<IContent>(contentLink);
        if (content is IContentMedia)
        {
            args.Context.Url.Host = editHost.Url.Host;
            args.Context.Url.Port = editHost.Url.Port;
            args.Context.Url.Scheme = editHost.Url.Scheme;
            args.IsCacheable = false;
        }
    }
}
#320969
Apr 24, 2024 12:06
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.