LinkURL-problem

Vote:
 

Hi!
I'm having problem with getting proper friendly links in a menu list. The code looks like this:

<EPiServer:MenuList ID="mnuList" NumberOfLevels="1" PageLink="1" runat="server" EnableViewState="false">
  <ItemTemplate><a href="<%#Container.CurrentPage.LinkURL %>"><img ....

The problem is that the links always are in the same base language and not the current language that the rest of the page is. Any ideas on how to fix this? Running first release of EpiServer CMS 5.

Thanks!

//Fredrik

#33122
Oct 02, 2009 11:47
Vote:
 

Hi,

This should normally go automatically. Do you use Fallback languages? 

As a workaround you can create a method like this:

protected string GetPageUrl(PageData page)
{
   return DataFactory.Instance.GetPage(page.PageLink, LanguageSelector.AutoDetect     ()).LinkURL;
   //or to get the spesific page language:
   //PageData thispage = DataFactory.Instance.GetPage(page.PageLink, new     LanguageSelector(CurrentPage.LanguageID));
}

 and use this instead of  <%#Container.CurrentPage.LinkURL %> like this

<%# GetPageUr(Container.CurrentPage) %> 

 

But again: this is just a quickfix since EPiServer should do this automatically and you should look into why it's not doing that. 

#33134
Oct 02, 2009 15:54
Vote:
 

There is a bug with LinkURL

I have to use thos code to get the LinkURL to give me the correct value

string linkUrl = page.LinkURL;
if (linkUrl.EndsWith("&epslanguage=en"))
    linkUrl = linkUrl.Replace("&epslanguage=en", "&epslanguage=" + page.LanguageID);
UrlBuilder url = new UrlBuilder(EPiServer.Configuration.Settings.Instance.SiteUrl + linkUrl);
EPiServer.Global.UrlRewriteProvider.ConvertToExternal(url, page.PageLink, UTF8Encoding.UTF8);

#33152
Edited, Oct 02, 2009 18:24
Vote:
 

The code for LinkURL get is like this and I cant see any reference to LanguageID property so it seems like it depends on PreferredCulture which is the active languages.

 

public string LinkURL
{
    get
    {
        string str = (string) this.GetValue("PageLinkURL");
        if (string.IsNullOrEmpty(str))
        {
            return string.Empty;
        }
        switch (this.LinkType)
        {
            case PageShortcutType.Normal:
            case PageShortcutType.FetchData:
            case PageShortcutType.Shortcut:
            {
                PageReference pageLink = this.PageLink;
                if ((DataFactory.Instance.IsWastebasket(pageLink) || (pageLink == PageReference.RootPage)) || this.IsDeleted)
                {
                    return str;
                }
                string name = ContentLanguage.PreferredCulture.Name;
                if (!LanguageSelection.IsHostLanguageMatch(name))
                {
                    string str3;
                    if (this._linkURLs.TryGetValue(name, out str3))
                    {
                        return str3;
                    }
                    str = UriSupport.AddLanguageSelection(str, name);
                    lock (this._linkURLs)
                    {
                        this._linkURLs[name] = str;
                    }
                }
                break;
            }
        }
        return str;
    }
}

 
 

 

#33153
Edited, Oct 02, 2009 18:30
Vote:
 

Thanks for the feedback!

The problem seems only to occur when the domain is used for setting the language. For instance domain.fi displays swedish links, but domain.se/fi/ displays finnish links. Strangely enough domain.fi/fi/ also display swedish links.

I've tried both suggestions for getting the page in a specific language, and it actually tells the fetched page is in finnish, but when written out it still becomes a swedish link.

The site uses fallback languages but not affecting the pages in the menu.

#33267
Oct 06, 2009 14:14
Vote:
 

Found the problem. There is no "epslanguage=fi" in the LinkURL at all, even if I fetch the page in a specific language.

The sollution was to check the presence of "&epslanguage" in the string from LinkURL and if not append it as "&epslanguage=" + page.LanguageBranch.

#33270
Oct 06, 2009 14:45