Im trying to get the NiceUrl of a published node in a UserControl, but I always get a empty string back. The strang thing is that when I'm debugging and I look through all the properties of the Node object the NiceUrl is filled! I've got no idea how to solve this problem. Please help! I'm using Umbraco 4.5.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Node node = Node.GetCurrent();
if (node.Children.Count > 0)
{
//Get the QueryString.
string queryString = HttpContext.Current.Request.QueryString.ToString();
//Do a 301 redirect to the first child node.
//If a QueryString is available this should also be passed.
Response.RedirectPermanent(string.Concat(node.Children[0].NiceUrl, string.IsNullOrEmpty(queryString) ? null : string.Concat("?", queryString)));
}
}
}
I want to do a 301 redirect to the first child node.
You said the NiceUrl is filled for the Node object. Are you checking the NiceUrl for the parent node or for the child node (which is being passed) when debugging?
I'm checking it for the child node. While debugging I do a quickwatch on "node.Children[0].NiceUrl" and that's empty. When I do a quickwatch on "node.Children[0]" and I look at the NiceUrl property it is filled :s.
Node properties empty
Hello,
Im trying to get the NiceUrl of a published node in a UserControl, but I always get a empty string back. The strang thing is that when I'm debugging and I look through all the properties of the Node object the NiceUrl is filled! I've got no idea how to solve this problem. Please help! I'm using Umbraco 4.5.
Jeroen
Hello Jeroen
Are you using umbraco.library.NiceUrl(int nodeId) or just Node.Url?
Regards,
Rune
Can you post your code?
Here is my code:
I want to do a 301 redirect to the first child node.
Jeroen
You said the NiceUrl is filled for the Node object. Are you checking the NiceUrl for the parent node or for the child node (which is being passed) when debugging?
I'm checking it for the child node. While debugging I do a quickwatch on "node.Children[0].NiceUrl" and that's empty. When I do a quickwatch on "node.Children[0]" and I look at the NiceUrl property it is filled :s.
The NiceUrl property remains empty. For now I use library.NiceUrl(node.Children[0].Id) as a temporary solution.
is working on a reply...