Virtual Nodes, how to determine the correct root site node from RequestContext
I am working in a multi-site umbraco, so I have multiple root nodes for multiple domains. I have a need to create virtual rows (deriving from UmbracoVirtualNodeRouteHandler).
In the FindContent() method, I have access to the RequestContext and the umbracoContext. (see below).
My question is, given this information, how do I determine which root node corresponds to the request?
I'm not sure I quite understand what you are trying to do, but I think what you are saying is you MapUmbracoRoute rule is 'relative' and therefore is matched on all of the sites, which you might want to be the case, but you need to know when you associate the relevant Umbraco Node with the route - which site the incoming request is intended for?
... Anyway one thing to be aware of is the UmbracoContext object that gets passed to your UmbracoVirtualNodeRouteHandler, and this contains a property containing the original request Url.
This will give you the domain of the request, and 'you could' use the Umbraco DomainService to find the root node id of the site corresponding to the requested domain, to give you your site context:
eg
int? rootContentId;
var ds = ApplicationContext.Current.Services.DomainService;
IDomain matchingDomain = ds.GetByName(domainName);
if (matchingDomain!=null){
rootContentId = matchingDomain.RootContentId;
}
I say 'could' because the DomainService will make a SQL request, and that's likely to slow down your site if it occurs on every request, depending on the makeup of your multi-tenancy site and how often urls change, it may be more pragmatic, to just have a simple lookup dictionary here to map domain to umbraco id, eg if domain == "fish.com" then rootId is 22....
The other approach would be to map a specific relative route for each site eg:
RouteTable.Routes.MapUmbracoRoute(
"Product list by category for uk",
"uk/category/{id}",
new
{
controller = "Category",
action = "ProductsByCategory",
id = UrlParameter.Optional,
page = 1,
site = "UK",
},
new UmbracoYourVirtualNodeRouteHandler("UK"));
}
RouteTable.Routes.MapUmbracoRoute(
"Product list by category for usa",
"us/category/{id}",
new
{
controller = "Category",
action = "ProductsByCategory",
id = UrlParameter.Optional,
page = 1,
site = "USA",
},
new UmbracoYourVirtualNodeRouteHandler("USA"));
}
etc
anyway is that close to what you were asking, apologies if I've missed the gist!
Virtual Nodes, how to determine the correct root site node from RequestContext
I am working in a multi-site umbraco, so I have multiple root nodes for multiple domains. I have a need to create virtual rows (deriving from UmbracoVirtualNodeRouteHandler).
In the FindContent() method, I have access to the RequestContext and the umbracoContext. (see below).
My question is, given this information, how do I determine which root node corresponds to the request?
bump. Anyone have any ideas about this?
Hi John
I'm not sure I quite understand what you are trying to do, but I think what you are saying is you MapUmbracoRoute rule is 'relative' and therefore is matched on all of the sites, which you might want to be the case, but you need to know when you associate the relevant Umbraco Node with the route - which site the incoming request is intended for?
In pure MVC you can create a DomainRoute for this kind of scenario: https://blog.maartenballiauw.be/post/2015/02/17/domain-routing-and-resolving-current-tenant-with-aspnet-mvc-6-aspnet-5.html but this won't work with MapUmbracoRoute as much as far as I can tell...
... Anyway one thing to be aware of is the UmbracoContext object that gets passed to your UmbracoVirtualNodeRouteHandler, and this contains a property containing the original request Url.
This will give you the domain of the request, and 'you could' use the Umbraco DomainService to find the root node id of the site corresponding to the requested domain, to give you your site context:
eg
I say 'could' because the DomainService will make a SQL request, and that's likely to slow down your site if it occurs on every request, depending on the makeup of your multi-tenancy site and how often urls change, it may be more pragmatic, to just have a simple lookup dictionary here to map domain to umbraco id, eg if domain == "fish.com" then rootId is 22....
The other approach would be to map a specific relative route for each site eg:
etc
anyway is that close to what you were asking, apologies if I've missed the gist!
regards
Marc
Thanks Marc, that lead me to where I needed to go. :-)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.