Copied to clipboard

Flag this post as spam?

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


  • Andrei 64 posts 115 karma points
    Oct 03, 2012 @ 17:50
    Andrei
    0

    c#: getting current site root node from a /base method in multisite solution

    Hi all,

    I have  a multisite solution and each site has it's own settings folder. The problem I have is that inside a /base method, I need to read some settings for the current site I'm in, but I coudn't yet figure a way to retrieve the root node.

    Usually when a normal page is requested, I can find which is the root node for the current site, starting from Node.GetCurrent().Path. (where the second id in the path string is the id of the root node in current site). And once I have root node I can find the settings for that site.

    But when a /base method is called, there is no context node, so Node.GetCurrent() is, of course, crashing. How can I find my root node in this case?

  • Hendy Racher 859 posts 3821 karma points MVP admin c-trib
    Oct 03, 2012 @ 17:56
    Hendy Racher
    0

    Hi Andrei,

    How about passing the Current ID (or Root ID) into the /Base method ?

  • Andrei 64 posts 115 karma points
    Oct 04, 2012 @ 13:15
    Andrei
    0

    Hi Hendy,

    Yes, that could be a workaround, but not the most elegant one I was hoping for as I would have to alter all ajax methods logic and make sure to always handle an id parameter. I was hoping for a more elegant way similar to Node.GetCurrent() in the normal page request.

    Surely, there must be a way, since umbraco is also resolving urls to nodes somehow for a specific site, so it has to be aware of the root node at some point.

    Another way I thought about was to iterate all level 1 nodes, and take the first node matching the value of HttpContext.Current.Request.Url.Host. Not sure though if this way is safe enough.  

  • Salli 12 posts 32 karma points
    Oct 05, 2012 @ 07:16
    Salli
    0

    I found a post here:

    http://our.umbraco.org/forum/developers/api-questions/7632-How-to-get-topnodes

    that might be what you're after, or at least point you in the right direction.

     

    HTH :)

Please Sign in or register to post replies

Write your reply to:

Draft