Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I am trying to get the IContent from the URL
For Example
I have url http://localhost:8080/abc/xyz then how to get the IContent from the url above in umbraco 7 and above.
I have tried
var content = UmbracoContext.Current.ContentCache.GetByRoute("http://localhost:8080/abc/xyz ");
or
var content = UmbracoContext.Current.ContentCache.GetByRoute("/abc/xyz ");
but no luck.
Hi Keyur
The UmbracoContext.Current.ContentCache.GetByRoute accepts a simple path eg your second option:
var content = UmbracoContext.Current.ContentCache.GetByRoute("/abc/xyz");
see: https://our.umbraco.org/apidocs/csharp/api/Umbraco.Web.PublishedCache.IPublishedContentCache.html
however if you have a domain set on your Umbraco tree, then the route needs to include the Id of the domain node in order to work eg
var content = UmbracoContext.Current.ContentCache.GetByRoute("123/abc/xyz");
Where 123 is the id of the node the domain is set on
Have a look at Tim Geyssens' UmbracoPageNotFoundHandler plugin source as a good example of this in use:
https://github.com/TimGeyssens/UmbracoPageNotFoundManager/blob/master/PageNotFoundManager/PageNotFoundContentFinder.cs
hope that helps
regards
Marc
Thanks Marc,
This really helps.
Though, when we have multiple content at root lever / same level at the site and no domain associated with it. In such case how to find the content similar to example above.
Thanks, Keyur
I've not tried to get a route when there are multiple top level nodes without domains.
I've just create a dummy site based on the Fanoe starter kit, and created multiple such top level nodes.
I'm finding in this circumstance the
approach works.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to get IContent from the Url or by route
I am trying to get the IContent from the URL
For Example
I have url http://localhost:8080/abc/xyz then how to get the IContent from the url above in umbraco 7 and above.
I have tried
var content = UmbracoContext.Current.ContentCache.GetByRoute("http://localhost:8080/abc/xyz ");
or
var content = UmbracoContext.Current.ContentCache.GetByRoute("/abc/xyz ");
but no luck.
Hi Keyur
The UmbracoContext.Current.ContentCache.GetByRoute accepts a simple path eg your second option:
see: https://our.umbraco.org/apidocs/csharp/api/Umbraco.Web.PublishedCache.IPublishedContentCache.html
however if you have a domain set on your Umbraco tree, then the route needs to include the Id of the domain node in order to work eg
Where 123 is the id of the node the domain is set on
Have a look at Tim Geyssens' UmbracoPageNotFoundHandler plugin source as a good example of this in use:
https://github.com/TimGeyssens/UmbracoPageNotFoundManager/blob/master/PageNotFoundManager/PageNotFoundContentFinder.cs
hope that helps
regards
Marc
Thanks Marc,
This really helps.
Though, when we have multiple content at root lever / same level at the site and no domain associated with it. In such case how to find the content similar to example above.
Thanks, Keyur
Hi Keyur
I've not tried to get a route when there are multiple top level nodes without domains.
I've just create a dummy site based on the Fanoe starter kit, and created multiple such top level nodes.
I'm finding in this circumstance the
approach works.
is working on a reply...