0

There is a similar questions but sadly there's no help in there.

I'm trying to create a CustomLinkProvider in Sitecore 9.3 and I have 2 problems:

  1. The LinkProvider() is Obsolete. What should I use instead?
  2. The problem I'm solving is the following: I have a multisite solution. If an item from Site1 links to an item from Site2, I need whole url: options.AlwaysIncludeServerUrl = true;

The code is the following:

public override string GetItemUrl(Item item, ItemUrlBuilderOptions options)
    {
        if (!item.Paths.FullPath.Contains(Sitecore.Context.Site.StartItem))
        {
            options.AlwaysIncludeServerUrl = true;
        }

        return base.GetItemUrl(item, options);
    }

And the app config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <linkManager>
      <providers>
        <add name="sitecore">
          <patch:attribute name="type">namespace_name.CustomLinkProvider,dll_name</patch:attribute>
        </add>
      </providers>
    </linkManager>
  </sitecore>
</configuration>

This is not working, nor I can't debug it. Is it because it is obsolete? Any feedback, help is very welcome. Ty.

1
3

The problem you are trying to solve, rendering the full URL with host name, does not require a custom link provider since this behaviour is available out of the box.

There are 2 settings which control this, both of which are true by default in 9.3 (they have been true for a number of versions).

<!--   SITE RESOLVING
       While rendering item links, some items may belong to different site. Setting this to true
       make LinkManager try to resolve target site in order to use the right host name.
       Default value: true
-->
<setting name="Rendering.SiteResolving" value="true"/>

<!--   RENDERING - SITE RESOLVING MATCH CURRENT SITE
       Affects how cross-site links are rendered when Rendering.SiteResolving is enabled.
       If true, the link provider will check if the target item is located under the start item for the current site before it
       tries to find a match in the full list of site definitions. This ensures that when the target item can be resolved using
       the current site, the target link will not change to a different site/hostname.
       Default value: true
-->
<setting name="Rendering.SiteResolvingMatchCurrentSite" value="true"/>

If this is not working then you should check:

  • If your <site> definition has multiple pipe (|) separated hostName entries then a single targetHostName property has been set
  • You are using an out of the box link provider, or your custom implemnentation takes these settings into account.

If these settings are not working then it could be a bug and you should raise it with Sitecore Support.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.