Oh, btw, just found the root reason to why I had to replace XhtmlString with string in my view model. This comes from built-in XhtmlStringJsonConverter:
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { XhtmlString xhtmlString = value as XhtmlString; if (xhtmlString == null) writer.WriteValue(string.Empty); else writer.WriteValue(xhtmlString.ToEditString()); }
It can't be intended to always use .ToEditString() in this case, right?
Ok, but do you have any idea of how I can get rewritten URLs when calling ToHtmlString? Is this a bug?
Which formatter/serializer is your WebAPI using? To me it seems that it somehow fetches all registered JsonConverters from IOC container and registers them, XhtmlString it self does not have any JsonConverter attribute.
I just stumbled on this as well that using .ToHtmlString() on a XhtmlProperty in a be controller to be sent to fe for rendering and internal links is rendered in "internal style .aspx". Running 12.13.
Mattias Olsson how did you solve your issue?
Hi!
When calling ToHtmlString on a XhtmlString property, the internal links are not rewritten. They are in ~/link/cdc1e0bb0f854b579fced7ded775e568.aspx format. How can I solve this?
I tried to do an ugly workaround like this, but then I get the CMS edit URL for the page, which leads to anonymous users being redirected to login page:
Can someone please explain why I get the edit URL (eg. /EPiServer/CMS/Content/mylink,,30/) when calling UrlResolver.Current.GetUrl(content.ContentLink, null, new VirtualPathArguments { ContextMode = ContextMode.Default })?
The scenario is I'm returning JSON from a WebAPI controller.