Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • stephencai 21 posts 131 karma points
    Oct 25, 2019 @ 06:17
    stephencai
    0

    Umbraco 7 Api Controller get content url with language

    Hi all,

    Currently, i got an issue when I am getting the url of item in "UmbracoApiController".

    The url always return default language, which is "/xxxx" instead of "/zh-HK/xxxx" I have set the Culture on umbraco and also add these code before I get the content url.

    Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-HK");
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(language.Replace("zh-HK");
    

    var url = item.Url;

    Any ideas or solution for this case?

  • Ben Abbott 19 posts 124 karma points
    Oct 25, 2019 @ 16:47
    Ben Abbott
    0

    I think custom Umbraco API's that inherit from UmbracoApiController aren't culture aware. The URL will always be ~/Umbraco/Api/Controller/action no matter which site you call them from.

    If you need your API method to know what culture to use, you may have to pass it as a parameter. Something like...

    ~/Umbraco/Api/Controller/action?culture=enGB

  • stephencai 21 posts 131 karma points
    Nov 07, 2019 @ 03:01
    stephencai
    0

    Hi Ben, Sorry for late reply. Yea, I have already pass the language through the parameter, and set the culture. The value which i get from vorto field is fine and correct. However, when i get the item.Url, the URL is always English. So i need to do the modification myself such as add the /lang/ before the url. Is there any wrong? Or it is normal.....

    Thanks~

Please Sign in or register to post replies

Write your reply to:

Draft