Anybody got any good suggestions on how to get the reffering pages NodeID? (ie, when you navigate to a page, I want to know the ID of the page you've just come from)
Yeah, that would just be like a screenscrape of the page.
I guess if I wanted to do this I would do something like set a cookie with the current nodeId on each page and read it before I change it to the new nodeId.
Do you mean you want to know if the ID of /Home if the user has gone /Home -> /Home/About-Us ?
You'd need to have some kind of reverse-NiceUrl using the referrer on the HttpRequest.UrlReferrer property. I'd probably do this all in .NET, I think trying to do it in XSLT would be a bitch :P
You'd have to speak to the uComponents guys, I'm not on that project :P
But this should get you started:
var referrer = Request.UrlReferrer.AbsoluteUrl;
var parts = referrer.Split('/');
var xpath = "/";
foreach(var part in parts)
{
xpath += "/*[@nodeName='" + part + "]";
}
xpath += "/@id";
That'll get you an XPath statement you can throw at a method in umbraco.library to execute and get your ID.
Note - I just wrote this in notepad so it's not tested, and it only supports directory URLs, you'll have to strip the .aspx from the end if you have to
The idea would be to grab the referrer from the request headers, and then split the url into an xpath statement. Should be relatively straightforward. You then get the umbraco node of the referrer, including its ID.
Let us know how you finally resolve this, it's an interesting question.
There used to be a stats module in the Umbraco core (you'd enable the "umbracoEnableStat" setting in the Web.config), but that seems to have been removed in v4.5! (not sure why?)
One suggestion could be to use "umbraco.requestHandler.CreateXPathQuery" to take the URL ... then use that XPath to get the node info?
@Lee - it was removed in v4 (or maybe even v3), there was a few pieces of legacy code that lay around that we removed for 4.5. The code wasn't doing anything.
FWIW, the 'umbracoEnableStat' entry was from the very first 'pro' product from Umbraco... Umbraco Stats. It came out around the end of v2 and was shelved during the life of v3. You can google more about it you're interested in the history.
In any event, the entry didn't do anything unless you had the product installed.
cheers, doug. (they guy with a mind like a steel trap... nothing gets in... no, wait, out! ... oh, nevermind)
I'm sure Stats was part of Umbraco v3 core. I remember playing around with it - trying to figure out how I could use it. But never used it on a "real world" project!
So... begs the question to why is "umbracoEnableStat" still in the appSettings? (not that it really matter, more curious)
@Lee - you're partly right that it was partly in the core and made some tables and populated them. That was the part with the performance problem and so it shouldn't be used.
:-) I was looking for something similar the other day (node id by url), and following the ideas of Slace and Lee here, pieces got together nicely now. Perhaps this could be of use in uComponents?
@jonas - Definatley. As I'm on the team now (@Lee finaly let me in ;) I can add it to the library if you'd like. Or you can ask @Lee/@Shanon to add you.
I'm trying to do something similar here but am running into an exception using the supplied code. If I debug through, I see the following values being set:
Thanks, Jonas, that fixed the exception. For some reason the SelectSingleNode call doesn't find my page but at least it's no longer throwing an error. I'll see if I can figure out why it can't locate the referring page in the content.Instance.XmlContent.
Just tried using this but it does not like me passing through referrer as it has the query string attached. Need a way of stripping that off but thats pushing a lot of code into my XSLT which I think should just be in the C#...any ideas?
That did the trick and enough to get me running. I use this to work out if I should inject a "history.back()" click event for a "Back to search" button (god I hate these...)
Getting the referring pages NodeID?
Hey Guys,
Anybody got any good suggestions on how to get the reffering pages NodeID? (ie, when you navigate to a page, I want to know the ID of the page you've just come from)
Cheers
Matt
Hi Matt
Off the top of my head cant you use the GetXmlDocumentByUrl(URL) and get the URL variable using the RequestServerVariables(referrer)
Then query the XML returned?
Thanks
Tom
Hi Tom,
Wouldn't GetXmlDocumentByUrl try to load the refering page as XML? rather than get the xml for the refering page?
Matt
Yeah, that would just be like a screenscrape of the page.
I guess if I wanted to do this I would do something like set a cookie with the current nodeId on each page and read it before I change it to the new nodeId.
Do you mean you want to know if the ID of /Home if the user has gone /Home -> /Home/About-Us ?
You'd need to have some kind of reverse-NiceUrl using the referrer on the HttpRequest.UrlReferrer property. I'd probably do this all in .NET, I think trying to do it in XSLT would be a bitch :P
How about in page load...
int previousNodeId = 0;
int.TryParse(Session["last_page"], out previousNodeId);
Session["last_page"] = Node.GetCurrent().Id
@slace that might be another nice one for uComponent extension library?
@sebastiaan / @dave, not bad suggestions. Might do the trick.
Matt
You'd have to speak to the uComponents guys, I'm not on that project :P
But this should get you started:
That'll get you an XPath statement you can throw at a method in umbraco.library to execute and get your ID.
Note - I just wrote this in notepad so it's not tested, and it only supports directory URLs, you'll have to strip the .aspx from the end if you have to
Hi Matt,
Couldn't you assign the GetXmlDocumentByUrl to a variable and then query that variable?
eg
<xsl:value select="GetXmlDocumentByUrl(URL)/@id"/>
Or something similar
Tom
You might be able to get clever with umbraco.library:GetXmlNodeByXpath()
http://our.umbraco.org/wiki/reference/umbracolibrary/getxmlnodebyxpath
The idea would be to grab the referrer from the request headers, and then split the url into an xpath statement. Should be relatively straightforward. You then get the umbraco node of the referrer, including its ID.
Let us know how you finally resolve this, it's an interesting question.
cheers,
doug.
Hey Matt,
There used to be a stats module in the Umbraco core (you'd enable the "umbracoEnableStat" setting in the Web.config), but that seems to have been removed in v4.5! (not sure why?)
One suggestion could be to use "umbraco.requestHandler.CreateXPathQuery" to take the URL ... then use that XPath to get the node info?
Cheers, Lee.
@Lee - it was removed in v4 (or maybe even v3), there was a few pieces of legacy code that lay around that we removed for 4.5. The code wasn't doing anything.
works for me:
ref: umbraco » presentation » umbracoBase » requestHandler.cs
FWIW, the 'umbracoEnableStat' entry was from the very first 'pro' product from Umbraco... Umbraco Stats. It came out around the end of v2 and was shelved during the life of v3. You can google more about it you're interested in the history.
In any event, the entry didn't do anything unless you had the product installed.
cheers,
doug. (they guy with a mind like a steel trap... nothing gets in... no, wait, out! ... oh, nevermind)
I'm sure Stats was part of Umbraco v3 core. I remember playing around with it - trying to figure out how I could use it. But never used it on a "real world" project!
So... begs the question to why is "umbracoEnableStat" still in the appSettings? (not that it really matter, more curious)
Cheers, Lee.
Cuz those lazy sods on the core haven't removed it :P
@Jonas - Niiiice, I'll go give that a try =)
Matt
@Lee - you're partly right that it was partly in the core and made some tables and populated them. That was the part with the performance problem and so it shouldn't be used.
This is an ancient forum post that has all the relevant info (along with some not-so-relevant-info) if you're up for some ancient history and why you should probably never enable the stats feature. http://forum.umbraco.org/yaf_postst4616_umbracoStats-changing-to-umbracoReports.aspx
cheers,
doug.
@Jonas - Worked like a charm. Nice snippet.
Matt
:-) I was looking for something similar the other day (node id by url), and following the ideas of Slace and Lee here, pieces got together nicely now. Perhaps this could be of use in uComponents?
@jonas - Definatley. As I'm on the team now (@Lee finaly let me in ;) I can add it to the library if you'd like. Or you can ask @Lee/@Shanon to add you.
Matt
Hey Jonas,
One step ahead... already added it to uComponents v2 (release in the next few weeks).
I'll make sure to give you credit in the XML comments! ;-)
Cheers, Lee.
Ah, cool, you're fast as lightning!
Cheers!
I'm trying to do something similar here but am running into an exception using the supplied code. If I debug through, I see the following values being set:
url: /the-sporting-life/event-calendar.aspx
realUrlXPath: /root/* [ = \"the-sporting-life\"]/* [ = \"event-calendar\"]
And then I get an exception on this line:
System.Xml.XmlNode urlNode = umbraco.content.Instance.XmlContent.SelectSingleNode(realUrlXPath);
The exception is: "System.Xml.XPath.XPathException: Expression must evaluate to a node-set." Any ideas what I'm doing wrong?
Thanks!
Matt
Hi Matt,
That's weird, the XPath expression is wrong - the predicates are missing the @urlName attribute!
How are you getting the "realUrlXPath" value? Is it by using the "CreateXPathQuery" method? or another way?
Cheers, Lee.
Ah, remove the ".aspx":
Thanks, Jonas, that fixed the exception. For some reason the SelectSingleNode call doesn't find my page but at least it's no longer throwing an error. I'll see if I can figure out why it can't locate the referring page in the content.Instance.XmlContent.
Just tried using this but it does not like me passing through referrer as it has the query string attached. Need a way of stripping that off but thats pushing a lot of code into my XSLT which I think should just be in the C#...any ideas?
@Pete, Could go for something like this...
The "Path" property isn't available on the UrlReferrer, (not sure why).
Cheers, Lee.
Hacked it in XSLT the end, just wanted to know if the referring page was from a particular page on the site:
That did the trick and enough to get me running. I use this to work out if I should inject a "history.back()" click event for a "Back to search" button (god I hate these...)
Cheers
Pete
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.