I’m new to Litium and trying to achieve some basic things programatically. For example getting a page using a given url. I am using Litium 7. Using this line of code var page = _pageService.Get(new Guid(id));
I can get the page through the id but how can I get the page (or the Id of the page) based on an url?
But why do you want to do a reverse lookup on the URL? Maybe there’s another way to accomplish what you’re looking for.
Data service hits the database directly, so you might have to cache the result depending on when it’s used. It should also be possible to use Lucene search to find the page.
It exists several options to find the page based on url-slug but it’s depend on what the purpose why we need to find the page by the url what method that suits the need best.
sorry for the late reply! I’m playing around with the possibility to build an spa and keeping the url structure so I guess the preferred way should be to get the page through the entire URL. But maybe there is a better way to achieve this?
In the project I’m working on this does not work either:
the url on each product is only the slug part for that page (the page url, not the complete url) so this is not working and using the dataservice for each call will not be good for performance.
This is now an internal API that may change in future but is the way that Litium it’self doing the url-lookups.
Inject the Litium.Web.Routing.PageRouteResolver and use the TryGet-method, the method return true/false depending on if the url exists and the out-parameter Litium.Web.Routing.RouteRequestInfo contains the data about the found page/category/product.
If the Litium.Web.Routing.RouteRequestInfo.Data is of the type Litium.Web.Products.Routing.ProductPageData the url will correspond to a category or product page.