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?
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.
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?
Hi Andrei,
How about passing the Current ID (or Root ID) into the /Base method ?
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.
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 :)
is working on a reply...