Umbraco - Select node by URL

情到浓时终转凉″ 提交于 2019-12-07 05:25:35

问题


I'm having issues with Umbraco when trying to get access to a node by it's url.

I've been trying to form an xpath query to select on the url, but I've no idea how to do that, and everything in their API is a 'dynamic' so I'm finding it impossible to dig much deeper for other methods.

The "Link to document" property in the Umbraco editor shows the path to be "/links/link-regions/link-region-1/". Its location in the editor is "/Data/Links/Link Regions/Link Region 1".

I suspect it'll look like this, but I cna't make it work:

//*[@url='/links/link-regions/link-region-1/']

I basically want to know what I have to do to get the node by providing either of these values and no others. I've been trying to do this for days now to no avail, please help!


回答1:


If you're using Umbraco 4.11 or later, there are a new set of APIs that allow you to retrieve strongly-typed content (as opposed to dynamic - which can be frustrating when trying to evaluate types when debugging).

UmbracoContext.Current.ContentCache.GetByRoute(string url) should do what you want.



来源:https://stackoverflow.com/questions/24450782/umbraco-select-node-by-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!