"URL to page/external address" property - Automatically option not working properly

Vote:
 

Hi,
I'm using EPiServer CMS 6 R2 for a website with two languages - English and German.
When I want to set a value of a property of type - "URL to page/external address" it does not take the proper language version of pages if Language dropdown is set to Automatically option. It works properly only if I select the specific language version from the dropdown.
For example:
When I'm in a German version of the site and I'm editing german version of a page. Clicking on property button will open "Select Page" dialog. From this dialog clicking on Select Page button will open correct language version of the site tree - the german one. Selecting a page will return you to Link Properties dialog with Language dropdown set to Automatically. Clicking on the OK button will return you to Edit Page, but the URL string will be neutral - "/SomePath/SomeName.aspx?id=20" instead of "/SomePath/SomeName.aspx?id=20&epslanguage=de"

#51423
Jun 08, 2011 10:29
Vote:
 

Does anyone have any idea for a workaround so I can get proper language URL from Link Properties dialog, without using custom properties or a way to set the current language as default value in Language dropdown.

#51909
Jun 28, 2011 10:52
Vote:
 

Hi

Just a clarification on how automatically option works. As you see it does not add any language information to the link when it is saved to the database. Instead it will add language infomration at request time. Say e.g that you have one page that has a link to another page with the link set to automattically. Then if you browse the first page in german then the link will be to the german version of the other page and if you instead view the page in english the link will be to the english version of the other page.

So at render time it will link to the page in the same language as you are currently browsing.

#51913
Jun 28, 2011 13:59
Vote:
 

OK

Thank you for this clarification. I got the idea.

It looks that our problems with "URL to page/external address" properties are actualy related to this bug:
http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=33122&epslanguage=en

It seems that links are working correctly in most situations, but I still can see problems in XHTML properties with links to EPi pages and Language dropdown set to Automatically. This is the string that XHTML property returns, which by your logic is correct:
<DIV>This is test link <A title="link title" href="/Templates/Public/Pages/TestPage.aspx?id=17663">text</A></DIV>


If I put this string in a Literal control instead of correct language link (german for example) the URL is for default version. The good news is that at least the default Language dropdown value is the current language when you try to add a link in a XHTML property.

 

#51921
Jun 28, 2011 16:59
Vote:
 

Hi Boyan!

We are not 100% certain of what you are doing but it might be that you are using the value of the property direcly and putting that into a Literal. In that case you will just get the raw value of the link. The property control resolves the actual external value of the link but in CMS 6 R2 you might also call ToWebString() on the property directly to get the resolved link.

#51927
Jun 29, 2011 7:58
Vote:
 

Hi!

Did you find a solution to this? I have the exact same problem on a cms 6 R2 site.

I have a site in both english and swedish.
I have a common page template with a "URL to page/external address" property on it.
If i use that property to create a link to a internal page and have the language dropdown set to automatic, it will always print the link without the language prefix.

If I for instance have a page in both english and swedish called "About us" and "Om oss" and select that page for the property on my common page template. It will resolve to "www.example.com/About-us" for the english version as it should, but it will resolve to "www.example.com/Om-oss/" instead of "www.example.com/sv/Om-oss" for the swedish version.

So it does not add the correct language prefix for the link url when the rewrite occures. I've tried printing the link several different ways, inlcuding with the EPiServer:property, code behind with ToWebString(), inline like <%= CurrentPage["MyProperty"] %>.

Note that this issue only occures when using the "URL to page/external address" property (by it self, or in a link collection etc). If I create the exact same link in the Text editor with language drop down set to automatic, it works fine.

Is there a solution for this? Or how should I correct this behaviour?

Brgds
Eric

#54596
Oct 24, 2011 10:52
Vote:
 

Hi!

I have tested and reproduced this (thanks for the nice repro). I'll file a bug for this but for now, here's some code to step around the issue until we fix it. The only thing you have to do is to make sure the epslanguage parameter is set in the link. In my case I did an override to the PropertyUrlControl class for the CreateDefaultControls with a helper method:

public override void CreateDefaultControls()
{
    HyperLink link = new HyperLink();
    link.Text = HttpUtility.HtmlEncode(ToExternalString());
    link.NavigateUrl = ToExternalString(); 

    if (!String.IsNullOrEmpty(CustomTagName))
    {
        HtmlGenericControl htmlControl = new HtmlGenericControl(CustomTagName);
        CopyWebAttributes(htmlControl);
        htmlControl.Controls.Add(link);
        Controls.Add(htmlControl);
    }
    else
    {
        CopyWebAttributes(link);
        Controls.Add(link);
    }
}

public string ToExternalString()
{
    string baseString = base.ToString();
    //Relative link, should be an EPi page.
    if (baseString.StartsWith("/"))
    {
        UrlBuilder mappedUrl = new UrlBuilder(baseString);
        mappedUrl.QueryLanguage = EPiServer.Globalization.ContentLanguage.PreferredCulture.Name;
        return (string)mappedUrl;
    }
    //Seems to be an external URL
    return baseString;
}

    

#54623
Oct 24, 2011 20:30
Vote:
 

Hi!

Thanks, good to know that it's an actual bug and not my coding :)

Your solution to the problem looks exellent, I'll try to implement that. I did a temporary solution myself, based on the same idéa where I add the epslanguage parameter to all links that are mappable, and does not already have the parameter (if I for instance wanted to link to an english page from the swedish version)

I did it by hooking in to the UrlRewriteProvider.ConvertingToExternal event in global.asax like below. (I fetch the languge from the pagedata for a special reason in my site, but you could just as well get it from globalization)

void UrlRewriteProvider_ConvertingToExternal(object sender, UrlRewriteEventArgs e)
        {
         //Extension to get current page data            
         PageData pd = HttpContext.Current.GetCurrentPage();

            if (pd != null)
            {
                if (e.IsMappableUrl && e.Url.QueryLanguage == null)
                    e.Url.QueryLanguage = pd.LanguageID;
            }
        }
#54629
Edited, Oct 25, 2011 8:45
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.