Sitecore 9.3 SXA lowercaseUrls is not working

Reference

https://doc.sitecore.com/developers/93/sitecore-experience-manager/en/build-item-and-media-urls.html
https://www.pintle.dk/insights/link-generation-in-sitecore-9-3/

Starting from Sitecore 9.3 there are changes to link generation functionality as well as enhancements to URL builder options configuration capabilities

The follow config comes from sitecore showconfig

<!--  URL BUILDERS  -->
<links>
    <urlBuilder>
        <alwaysIncludeServerUrl>false</alwaysIncludeServerUrl>
        <languageEmbedding>asNeeded</languageEmbedding>
        <languageLocation>filePath</languageLocation>
        <lowercaseUrls>true</lowercaseUrls>
        <encodeNames>true</encodeNames>
        <useDisplayName>false</useDisplayName>
    </urlBuilder>
    <!--  ITEM URL BUILDER
             Defines the url builder used for building items url.

             alwaysIncludeServerUrl :       Controls whether to always add the current server URL to generated URLs (DEFAULT: false)     
             languageEmbedding :            Controls when to embed the language name in generated URLs 
                                                OPTIONS: asNeeded | always | never (DEFAULT: asNeeded)
             languageLocation :             Controls where to embed the language name in generated URLs (DEFAULT: filePath)
                                                OPTIONS: filePath | queryString (DEFAULT: filePath)
             lowercaseUrls :                Controls whether to lowercase the generated URL (DEFAULT: false)
             encodeNames :                  Controls whether to encode the names making the generated URL (DEFAULT: true)
             useDisplayName :               Controls whether to use item display name (DEFAULT: false)
             addAspxExtension :             Controls whether to add '.aspx' extension to the generated URL (DEFAULT: false)
             siteResolving :                Controls whether to resolve site information while rendering item URL (DEFAULT: true)
             shortenUrls :                  Controls whether to shorten generated URLs (DEFAULT: true)
         -->
    <itemUrlBuilder type="Sitecore.Links.UrlBuilders.ItemUrlBuilder, Sitecore.Kernel">
        <param type="Sitecore.Links.UrlBuilders.DefaultItemUrlBuilderOptions, Sitecore.Kernel" desc="defaultOptions">
            <alwaysIncludeServerUrl ref="links/urlBuilder/alwaysIncludeServerUrl"/>
            <languageEmbedding ref="links/urlBuilder/languageEmbedding"/>
            <languageLocation ref="links/urlBuilder/languageLocation"/>
            <lowercaseUrls ref="links/urlBuilder/lowercaseUrls"/>
            <encodeNames ref="links/urlBuilder/encodeNames"/>
            <useDisplayName ref="links/urlBuilder/useDisplayName"/>
            <addAspxExtension>false</addAspxExtension>
            <siteResolving>true</siteResolving>
            <shortenUrls>true</shortenUrls>
        </param>
    </itemUrlBuilder>
    <!--  MEDIA URL BUILDER
             Defines the url builder used for building media items url.

             alwaysIncludeServerUrl :       Controls whether to always add the current server URL to generated URLs (DEFAULT: false).     
             languageEmbedding :            Controls when to embed the language name in generated URLs (DEFAULT: asNeeded).
             languageLocation :             Controls where to embed the language name in generated URLs (DEFAULT: filePath).
             lowercaseUrls :                Controls whether to lowercase the generated URL (DEFAULT: false).
             encodeNames :                  Controls whether to encode the names making the generated URL (DEFAULT: true).
             useDisplayName :               Controls whether to use item display name (DEFAULT: false).
             absolutePath :                 Controls whether to render media links as absolute (DEFAULT: false).
             includeExtension :             Controls whether to include media extension in generated URL (DEFAULT: true).
         -->
    <mediaUrlBuilder type="Sitecore.Links.UrlBuilders.MediaUrlBuilder, Sitecore.Kernel">
        <param type="Sitecore.Links.UrlBuilders.DefaultMediaUrlBuilderOptions, Sitecore.Kernel" desc="defaultOptions">
            <alwaysIncludeServerUrl ref="links/urlBuilder/alwaysIncludeServerUrl"/>
            <languageEmbedding ref="links/urlBuilder/languageEmbedding"/>
            <languageLocation ref="links/urlBuilder/languageLocation"/>
            <lowercaseUrls ref="links/urlBuilder/lowercaseUrls"/>
            <encodeNames ref="links/urlBuilder/encodeNames"/>
            <useDisplayName ref="links/urlBuilder/useDisplayName"/>
            <absolutePath>true</absolutePath>
            <includeExtension>true</includeExtension>
        </param>
        <param desc="mediaLinkPrefix">$(1)</param>
    </mediaUrlBuilder>
</links>

We are using Sitecore 9.3 SXA, when i try to set links/urlBuilder/lowercaseUrls = true, but it's doesn't work. I don't know why.
I found some LinkManager config comes from SXA

<linkManager defaultProvider="switchableLinkProvider" patch:source="Sitecore.XA.Foundation.Multisite.config">
    <providers>
        <clear/>
        <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" lowercaseUrls="true" resolve="true"/>
        <add name="switchableLinkProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.SwitchableLinkProvider, Sitecore.XA.Foundation.Multisite" patch:source="Sitecore.XA.Foundation.Multisite.config"/>
        <add name="localizedProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.LocalizableLinkProvider, Sitecore.XA.Foundation.Multisite" cacheExpiration="5" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false" patch:source="Sitecore.XA.Foundation.Multisite.config"/>
    </providers>
</linkManager>

I use dotPeek decompile the sitecore dll and found this.
Any patching config contions addAspxExtension, alwaysIncludeServerUrl, encodeNames, languageEmbedding, languageLocation, lowercaseUrls, useDisplayName, shortenUrls, and then the linkProvider will use Legacy config, doesn't using new config links/urlBuilder/lowercaseUrls

/// <summary>Initializes the provider.</summary>
    /// <param name="name">The friendly name of the provider.</param>
    /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
    /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception>
    /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception>
    /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)" /> on a provider after the provider has already been initialized.</exception>
    public override void Initialize(string name, NameValueCollection config)
    {
      Assert.ArgumentNotNullOrEmpty(name, nameof (name));
      Assert.ArgumentNotNull((object) config, nameof (config));
      base.Initialize(name, config);
      this._itemUrlBuilder = (ItemUrlBuilder) this._factory.CreateObject("links/itemUrlBuilder", true);
      this.LoadLegacyDefaultOptions(config);
    }

    private void LoadLegacyDefaultOptions(NameValueCollection config)
    {
      if (!this.IsLegacyOptionsSet(config))
        return;
      Log.SingleWarn("Obsolete link provider settings are used. Please use item url builder configuration to configure item url settings 'links/itemUrlBuilder' ", (object) this);
      this._itemUrlBuilder.DefaultItemUrlBuilderOptions.AddAspxExtension = MainUtil.GetBool(config["addAspxExtension"], false);
      this._itemUrlBuilder.DefaultItemUrlBuilderOptions.AlwaysIncludeServerUrl = MainUtil.GetBool(config["alwaysIncludeServerUrl"], false);
      this._itemUrlBuilder.DefaultItemUrlBuilderOptions.EncodeNames = MainUtil.GetBool(config["encodeNames"], true);
      this._itemUrlBuilder.DefaultItemUrlBuilderOptions.LanguageEmbedding = this.GetLanguageEmbedding(config["languageEmbedding"], LanguageEmbedding.AsNeeded);
      this._itemUrlBuilder.DefaultItemUrlBuilderOptions.LanguageLocation = this.GetLanguageLocation(config["languageLocation"], LanguageLocation.FilePath);
      this._itemUrlBuilder.DefaultItemUrlBuilderOptions.LowercaseUrls = MainUtil.GetBool(config["lowercaseUrls"], false);
      this._itemUrlBuilder.DefaultItemUrlBuilderOptions.UseDisplayName = MainUtil.GetBool(config["useDisplayName"], false);
      this._itemUrlBuilder.DefaultItemUrlBuilderOptions.ShortenUrls = MainUtil.GetBool(config["shortenUrls"], true);
    }

    private bool IsLegacyOptionsSet(NameValueCollection config)
    {
      return StringUtil.GetString(config["addAspxExtension"], config["alwaysIncludeServerUrl"], config["encodeNames"], config["languageEmbedding"], config["languageLocation"], config["lowercaseUrls"], config["useDisplayName"], config["shortenUrls"]).Length > 0;
    }

SO, There are two options for our purposes

  • Add lowercaseUrls="true" to sxa patching config
  • Remove all legacy config from sxa patching config

Option 1

<linkManager defaultProvider="sitecore">
    <patch:attribute name="defaultProvider">switchableLinkProvider</patch:attribute>
    <providers>
        <add name="switchableLinkProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.SwitchableLinkProvider, Sitecore.XA.Foundation.Multisite"/>
        <add name="localizedProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.LocalizableLinkProvider, Sitecore.XA.Foundation.Multisite" cacheExpiration="5" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false" lowercaseUrls="true"/>
    </providers>
</linkManager>

Option 2

<linkManager defaultProvider="sitecore">
    <patch:attribute name="defaultProvider">switchableLinkProvider</patch:attribute>
    <providers>
        <add name="switchableLinkProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.SwitchableLinkProvider, Sitecore.XA.Foundation.Multisite"/>
        <add name="localizedProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.LocalizableLinkProvider, Sitecore.XA.Foundation.Multisite" cacheExpiration="5"/>
    </providers>
</linkManager>

评论

还没有人评论,抢个沙发吧...

Viagle Blog

欢迎来到我的个人博客网站