GUID appearing instead of friendly url

Vote:
 

Hi

Episerver "XhtmlString" type field datatype value has a combination of text and one of the page references but when we open the publishing page reference it's showing https://domain/link/guid.aspx instead of  https://domain/level1/level2page

Could you please suggest a fix to make a friendly URL?

#269828
Edited, Jan 11, 2022 15:52
Vote:
 

Are you using XhtmlString.ToString() to assign a string property on a viewmodel? In that case you can use this extension method instead:

public static class XhtmlStringExtensions
{
    private static readonly Injected<IUrlResolver> InjectedUrlResolver;

    public static string ToHtmlStringWithUrls(this XhtmlString xhtmlString)
    {
        if (string.IsNullOrWhiteSpace(xhtmlString?.ToHtmlString()) || xhtmlString.IsEmpty)
        {
            return string.Empty;
        }

        var result = new StringBuilder();

        foreach (var fragment in xhtmlString.Fragments)
        {
            var urlFragment = ParseFragment(fragment);

            result.Append(urlFragment);
        }

        return result.ToString();
    }

    private static string ParseFragment(IStringFragment fragment)
    {
        var urlFragment = fragment as UrlFragment;
        if (urlFragment == null)
        {
            return fragment.GetViewFormat();
        }

        var url = InjectedUrlResolver.Service.GetUrl(new UrlBuilder(urlFragment.InternalFormat), GetContextMode());
        return url;
    }

    private static ContextMode GetContextMode()
    {
        return HttpContext.Current?.Request.RequestContext?.GetContextMode() ?? ContextMode.Default;
    }
}
#269837
Jan 11, 2022 18:43
* 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.