Copied to clipboard

Flag this post as spam?

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


  • Steve 140 posts 321 karma points
    Nov 23, 2015 @ 21:26
    Steve
    0

    Culture specific Url from IPublishedContent node in web api

    Hi All,
    I have a site with multiple domains for various languages, set in Culture and Hostnames under the Home node. In a web api, I would like to return the Url of a node, but with the link that is specific to the current language (ie the current domain). Using @item.Url in razor works fine - however from the web api the value returned is not specific to the current culture/domain. It seems to be returning a value consistent with the first item in the list of 'Link to Document' items under the Properties tab of the node - but perhaps just a coincidence.
    Does anyone know how to return the correct Url?
    Thanks, Steve

  • Peter Kongyik 28 posts 170 karma points
    Nov 24, 2015 @ 10:45
    Peter Kongyik
    0

    Hi Steve,

    In Razor UmbracoContext.Current.PublishedContentRequest.Culture is set to the Culture of the current node you view.

    I think this is missing when a Web Api request is made, it is worth try setting UmbracoContext.Current.PublishedContentRequest.

    How to do that however, unfortunately I'm not aware of, it seems you need to get an Umbraco.Web.Routing.RoutingContext which has internal constructor.

    Regards, Peter

  • Steve 140 posts 321 karma points
    Nov 24, 2015 @ 19:12
    Steve
    0

    Hi Peter,
    Yes, it seems like the culture settings are not available from within the web api.
    For anyone interested, I generated a functional url by building a string in the api using something similar to: item.parent.name + "/" + item.name and then getting the current culture in the view and passing that as razor variable into the javascript api .success function where the html is created.
    Steve

Please Sign in or register to post replies

Write your reply to:

Draft