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'm having real problems trying to get a node from its URL using the API - I want to be able to get at the node from its URL so I can return some JSON content, but I can't get anything sensible from umbraco.requestHandler.CreateXPathQuery - this returns
/root/* [ = "level1"]/* [ = "level2"]/* [ = "level3"]
which even I can tell is practically useless. Even when manually replacing the [ with [@urlName I still don't get anything useful back.
Help gratefully received.
there's a function in the library which might help you out:
That just takes an external URL and returns it so you can do things like parse tweets etc.
I want to take a URL for the umbraco site and retrieve its node from the NodeFactory ideally
The 'requestHandler.CreateXPathQuery' method should return you the appropriate XPath expression to locate the node.
The output you gave is that exactly what you are getting back? As it doesn't look right at all.
We use this approach in uComponents for an XSLT extension Url.GetNodeIdByUrl.
There might be an alternative approach to this, but depends on where you are calling your code from? You could attempt to access HttpContext.Current.Items["pageID"]?
I think this is deprecated in 4.7 as it was in the source for 4.6 and still shows in the binaries for 4.7, but I can't find it in the source for 4.7 on codeplex. I wonder if that's why it isn't returning anything useful anymore - it isn't used. It does beg the question, how does uComponents work when it calls it though.
I am actually trying to load some data in an ASP.Net Handler ashx which means that HttpContext.Current etc. won't hold anything useful at all. If there was an easier way, I'd be using it.
Not sure where you heard that 'CreateXPathQuery' had been depreciated? It is definitely still being used for Umbraco core to find the content node on page load.
Thinking you might be right about the HttpContext ... how about moving your code/logic from a HttpHandler to an Umbraco /Base (RestExtension) method?
We found our problem! The underlying
We're using this now:
string xpathQuery = umbraco.requestHandler.CreateXPathQuery(context.Request.QueryString["path"], false).Replace("[ ", "[@urlName ").Replace("/root/*", "/root//*");
Basically, the nodes we were looking at weren't directly under the root node - they were in a container which doesn't show up in the URL. The CreateXPathQuery method still doesn't return @urlName where necessary, so we still need to add this in with the replace above. The Umbraco 4.6 source has an initialization method which makes sure this is populated which we're not calling (they don't in uComponents either)
Anyway, panic over. For now.
I realise you've solved this, but there's a method in uCompontents uQuery called GetNodeByUrl(string) that sounds like it is what you require.
For a similar question, but for Umbraco 7 :
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted