I am currently trying to implement a custom not found handler for a given set of urls. The redirect page is to change dependant on what level the requested page should have been on (in essence there is going to be a default page that can be overridden if the correct node ACTUALLY exists)
As such, I am trying to get the node id for the default pages to act as the redirect node id when the handler is utilised, as the node id may well be different between staging and live or may change, I am trying to do this using the url of the node.
You could try something funky by using the CreateXPathQuery method in umbraco.requestHandler?
For example:
public static Int32 GetNodeIdFromUrl(String url)
{
Int32 nodeId = -1;
String xpath = umbraco.requestHandler.CreateXPathQuery(url, false);
if (!String.IsNullOrEmpty(xpath))
{
System.Xml.XmlNode node = umbraco.content.Instance.XmlContent.SelectSingleNode(xpath);
if ((node != null) && (node.Attributes != null))
{
Int32.TryParse(node.Attributes["id"].Value, out nodeId);
}
}
return nodeId;
}
I haven't given this code much testing, so you should play around with various properties to get the best results. I'd suggest passing through the URL parameter without the domain prefix.
Getting a node id from its url
Hey Folks
I am currently trying to implement a custom not found handler for a given set of urls. The redirect page is to change dependant on what level the requested page should have been on (in essence there is going to be a default page that can be overridden if the correct node ACTUALLY exists)
As such, I am trying to get the node id for the default pages to act as the redirect node id when the handler is utilised, as the node id may well be different between staging and live or may change, I am trying to do this using the url of the node.
How can I achieve this?
Thanks in advance
Hi cardinal252,
You could try something funky by using the CreateXPathQuery method in umbraco.requestHandler?
For example:
I haven't given this code much testing, so you should play around with various properties to get the best results. I'd suggest passing through the URL parameter without the domain prefix.
Good luck, and let us know how it works out!
Cheers, Lee.
is working on a reply...