With the new nuget package updates, we are getting stackoverflow errors with LinkURL on shortcut urls setup for international language pages to English (within the site). Can you check out follows and advise is this implementation is correct specifically the public static string ContentUrl(this IUrlHelper urlHelper, ContentReference contentLink, string queryStringAppend)
public static class UrlHelpers { /// <summary> /// Returns the target URL for a ContentReference. Respects the page's shortcut setting /// so if the page is set as a shortcut to another page or an external URL that URL /// will be returned. /// </summary> public static Microsoft.AspNetCore.Html.HtmlString LinkUrl(this UrlHelper urlHelper, ContentReference contentLink) { if (!contentLink.HasValue()) { return Microsoft.AspNetCore.Html.HtmlString.Empty; }
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); var page = contentLoader.Get<PageData>(contentLink);
return LinkUrl(urlHelper, page); }
/// <summary> /// Returns the target URL for a page. Respects the page's shortcut setting /// so if the page is set as a shortcut to another page or an external URL that URL /// will be returned. /// </summary> public static Microsoft.AspNetCore.Html.HtmlString LinkUrl(this UrlHelper urlHelper, PageData page) { var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>(); switch (page.LinkType) { case PageShortcutType.Normal: case PageShortcutType.FetchData: return new HtmlString(urlResolver.GetUrl(page.ContentLink));
case PageShortcutType.Shortcut: var shortcutProperty = page.Property["PageShortcutLink"] as PropertyPageReference; if (shortcutProperty != null && shortcutProperty.ContentLink.HasValue()) { return urlHelper.LinkUrl(shortcutProperty.ContentLink); } break;
case PageShortcutType.External: return new HtmlString(page.LinkURL); } return HtmlString.Empty; }
public static string ContentUrl(this IUrlHelper urlHelper, ContentReference contentLink, string queryStringAppend) { if (queryStringAppend.HasValue()) { if (contentLink.HasValue()) { var query = HttpUtility.ParseQueryString(queryStringAppend);
UrlBuilder builder = new UrlBuilder(UrlResolver.Current.GetUrl(contentLink)); builder.QueryCollection = query;
With the new nuget package updates, we are getting stackoverflow errors with LinkURL on shortcut urls setup for international language pages to English (within the site). Can you check out follows and advise is this implementation is correct specifically the public static string ContentUrl(this IUrlHelper urlHelper, ContentReference contentLink, string queryStringAppend)
public static class UrlHelpers
{ /// <summary>
/// Returns the target URL for a ContentReference. Respects the page's shortcut setting
/// so if the page is set as a shortcut to another page or an external URL that URL
/// will be returned.
/// </summary>
public static Microsoft.AspNetCore.Html.HtmlString LinkUrl(this UrlHelper urlHelper, ContentReference contentLink)
{
if (!contentLink.HasValue())
{
return Microsoft.AspNetCore.Html.HtmlString.Empty;
}
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var page = contentLoader.Get<PageData>(contentLink);
return LinkUrl(urlHelper, page);
}
/// <summary>
/// Returns the target URL for a page. Respects the page's shortcut setting
/// so if the page is set as a shortcut to another page or an external URL that URL
/// will be returned.
/// </summary>
public static Microsoft.AspNetCore.Html.HtmlString LinkUrl(this UrlHelper urlHelper, PageData page)
{
var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
switch (page.LinkType)
{
case PageShortcutType.Normal:
case PageShortcutType.FetchData:
return new HtmlString(urlResolver.GetUrl(page.ContentLink));
case PageShortcutType.Shortcut:
var shortcutProperty = page.Property["PageShortcutLink"] as PropertyPageReference;
if (shortcutProperty != null && shortcutProperty.ContentLink.HasValue())
{
return urlHelper.LinkUrl(shortcutProperty.ContentLink);
}
break;
case PageShortcutType.External:
return new HtmlString(page.LinkURL);
}
return HtmlString.Empty;
}
public static string ContentUrl(this IUrlHelper urlHelper, ContentReference contentLink, string queryStringAppend)
{
if (queryStringAppend.HasValue())
{
if (contentLink.HasValue())
{
var query = HttpUtility.ParseQueryString(queryStringAppend);
UrlBuilder builder = new UrlBuilder(UrlResolver.Current.GetUrl(contentLink));
builder.QueryCollection = query;
return builder.ToString();
}
}
return urlHelper.ContentUrl(contentLink);
}
}