Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Get friendly URL with language flag? : EPiServer

Vote:
 

My variable langURL currently returns a non-friendly URL like so: http://localhost:57299/link/457fee1669e348febf67ecb57b281945.aspx?epslanguage=de-AT

Is it possible to get a friendly URL?

public static IHtmlString HrefLangLinks(this PageData currentPage)
{

    var availablePageLanguages = currentPage.ExistingLanguages.Select(culture => culture.Name).ToArray();
    var Output = "";
    var langURL = "";

    foreach (string listitem in availablePageLanguages)
    {
        langURL = EPiServer.Web.UriUtil.AddLanguageSelection(currentPage.LinkURL, listitem);
        Output += "<link href=\"" + langURL + "\" hreflang=\"" + listitem + "\" rel=\"alternate\" >";
    }


    // Dictionary<String, String>
    return new HtmlString(Output.ToString());
}

For each page I would like to get the friendly urls with the language flag as well, for example:

  • /
  • /de-DE
  • /en-DE
#218713
Mar 19, 2020 6:42
Vote:
 

UrlResolver.GetUrl ?

Something like:

foreach(var lang in currentPage.ExistingLanguages)
{
     var langPrefix = lang.ToString();
     var url = UrlResolver.Current.GetUrl(currentPage.ContentLink, langPrefix);
}

If you need absolute urls you can use the current sitedefinition like: (I'm using the Flurl nuget package to combine urls to avoid handling all the slashes etc)

var currentSitePath = SiteDefinition.Current.SiteUrl;
foreach (var lang in currentPage.ExistingLanguages)
{
     var langPrefix = lang.ToString();
     var url = UrlResolver.Current.GetUrl(currentPage.ContentLink, langPrefix);
     var absoluteUrl = Flurl.Url.Combine(currentSitePath.ToString(), url);
}
#218720
Edited, Mar 19, 2020 7:52
* 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.