• Not Answered

Using a custom LinkProvider in order for multisite linking to work on CM

We have multiple sites in sitecore but alla are adited by the same editors and they want to be able to edit it all in one place. The majority of our editors use EE.

Problems: When you follow a link (on a page on EE) or search (in EE) on an item belonging to another site (than the one you are editing) it leads you to the full site address. In our case the public address of the site. We want it to lead directly to the editing of that page.


Main idea:

Why not just use id-parmeters style links (sc_itemid=...) when working on the cm server?


Try 1: Configure the standard link provider in Sitecore to only use ?sc_itemid=GUID - linking style.

I failed to do that. Maybe it is possible, but I don't know how


Try 2: Use a very simple custom link provider on CM.


        <add name="sitecore">
          <!-- Use an extremely simple link-provider on cm-servers, only sending id and language as parameters -->
          <patch:attribute name="type">Foundation.Url.UrlHandlers.IDLinkProvider, Foundation.Url</patch:attribute>


using Sitecore.Data.Items;
using Sitecore.Links;
namespace Foundation.Url.UrlHandlers
    class IDLinkProvider : [NORMAL LINK PROVIDER HERE]
        public override string GetItemUrl(Item item, UrlOptions options)
            // Use "parent" link provider if not content
            if (!item.Paths.IsDescendantOf(item.Database.GetItem(Sitecore.Constants.ContentPath))) return base.GetItemUrl(item, options);

            string lang = item.Language.Name;
            if (options?.Language != null) lang = options.Language.Name; // If lang provided in options, use it.
            string url = "/?sc_itemid=" + item.ID + "&sc_lang=" + lang; // Note the leading / to make it a full address. Required on for example the search in EE.
            if (Sitecore.Context.PageMode.IsExperienceEditor) url += "&sc_mode=edit";
            return url;

I tried with an even simpler LinkProvider first but then I had to add some checks for it to work like only use it for stuff under the content-item (or it destroyed links in content editor etc) and also the sc_mode=edit was not added or remembered in the cookie correctly in some situations.


Alternative idea:

Maybe I could have added this linkProvider as yet another link provider, set my new as the default one and use a fallback mechanism where I load and call the "sitecore" link provider, instead of calling base.



Is this a bad idea for some reason?

Have you got a better solution or improvements on this one?

1 Reply

  • Well the LinkProvider is the place to do things with link urls, so your on the right way, I don't see the sc_site url parameter in your code, do you not need it?