Virtual Happy Hour canceled for Friday May 31st.
Try our conversational search powered by Generative AI!
AI OnAI Off
Virtual Happy Hour canceled for Friday May 31st.
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;
}
}
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?