Developer Forum »
Find a node based on name?
62 posts
string targetUrl = HttpUtility.HtmlAttributeEncode(Request.QueryString["ReturnUrl"].ToString());
Uri uri = new Uri(targetUrl);
string targetPage = uri.Segments[uri.Segments.Length-1];
HierarchicalContent hc = WAFContext.Session.GetContent<HierarchicalContent>(targetPage);

I'm trying to retrieve a node based on information in a query parameter. I'm able to pick out the name (adress) of the node, but I get the error (System.Exception: No content of type HierarchicalContent could be found. ) when I try to retrieve the node based on this name. 

120 posts

Is it the address (.Address) you are looking for or the name (.Name)?

To get a content by name: WAFContext.Session.GetContent<ContentBase>(name); // name is string

To get a content by address, look at this:

WAFContext.Engine.GetMatchingAddresses(cleanedAddress, true);

Ole

62 posts

Thanks! Using GetMatchingAddresses works fine!

 

Anyway; what if I have this url: http://localhost:59105/Lokale-kontakter,

Should I then be able to retrieve the node by doing this? : WAFContext.Session.GetContent<ContentBase>("Lokale-kontakter");

(it doesn't work for me).

 

120 posts

Could you not use WAFContext.Request.GetContent() or WAFContext.Request.NodeId ?

(is it a MVC project?)

62 posts

No, I cannot use this method because I get the url (string) via a request parameter (see initial post in this thread).  It is Web Forms, not mvc.

1