I'm exactly sure how to word this so if this has already been answered then accept my apologies (!).
I'm using a UserControl to display to a logged in user what Member Groups have assigned to them. For each individual group there is going to be a matching page. So, for instance, if I have a member group called LimitedAccess then there will be a page called LimitedAccess.aspx.
What i'm trying to do is for each Member Group that I'm displaying to a member, I want to create a link that goe's off to the matching page. Originally I took the name of the member group and slapped '.aspx' on the end and all was well. But I've realised that a) this is a rubbish solution and b) this will only work if the matching document lives on a certain level within the content tree.
What I'd like to be able to do is to get the URL of the node by it's name (which I'll know from the member group) and then dynamically build the tags using this URL. The code snippet I'm currently using is below.
string[]roles=Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name); stringzLinkText; for(inti=0;i<roles.Length;i++) { if(roles[i]!="Standard") { zLinkText=roles[i].Replace(" ","");//Remove all spaces from the member role to create the link txtLoggedIn.Text+="<a href=\""+zLinkText+".aspx\">"+roles[i]+"</a>"+"<br/>"; } }
ZlinkText is just a string though......it doesn't currently relate to a document. I need to relate it to a document and that's what I'm unsure of how to do in UserControl.
You'll have to add some logic in to ensure that the user has access to the link you're displaying of course but this is just a way you can get the nodes.
Instead of having the node id you can always register the node in web.config and then call it like
var startNode = Convert.ToInt32(ConfigurationManager.AppSettings["whateverName"]));
Hi again Richard (and thanks for your help again!),
I haven't got the option to create 'new Node(1201)' (Intellisense isn't giving me anything to do with nodes) so I presume that I'm missing a namespace reference somewhere. I'm using
usingumbraco.cms.businesslogic.member;
To open up the Member Class but I don't know which one relates to the actual content of the site! All in all I don't know a lot!
You know that 1201 is the node of your parent/start node right?
Using Umbraco.NodeFactory is what you need to get that. A tip in VIsual Studio if you get the squiggly red underline, click on it and then press Ctrl+. (as in the dot character), this will bring up a list of available namespaces
Regarding showing which groups a user is a member of I'm not sure there is anything available in the API for that, so you may have to write a stored procedure for that.
The two database tables involved are cmsMember which shows the members and the member id and also cmsMember2MemberGroup whichshows which group(s) that member is related to.
It wouldn't take much to pull that information back in a stored procedure and display it.
But I'm wondering what your link is actually for since the member group isn't a node in the content tree.
What I've got is list of Member Groups and in the content of the site there 'pages' (for want of a better term) that are named the same as the Member Groups. ie. There's a Member Group called MyWebsitesSecureUser there somewhere in the content tree there's a page called MyWebsitesSecureUser.aspx. When a member logs in I'm getting all of the member groups that they are a member of displaying them on screen. But what I'm actually trying to do is create a clickable link so the logged in user not only see's the groups that they belong but they can click the link and be taken to the relevant page.
So while I know that somewhere in the content tree there's a document called MyWebsitesSecureUser.aspx I don't know what it's URL is (because it could exist at any level in the tree) so I need to find the page in the tree and then pull it's URL back and create the link.
I was sorta hoping that there'd be something like GetNodeByName(zMyPageName) in much the same way as I get the Member roles by the GetRolesForUser function....
There is a helper method in uQuery for this: "uQuery.GetNodesByName(string name)". If you are using Umbraco 4.8+ then uQuery is under the "umbraco" namespace, otherwise if you are using an earlier version, download an older version of uComponents (e.g. v3.x, v4.x).
An example code snippet would be:
var roles = Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name);
for (int i = 0; i < roles.Length; i++)
{
if (roles[i] != "Standard")
{
var memberGroup = roles[i]; // do whatever string manipulation here
var node = umbraco.uQuery.GetNodesByName(memberGroup).FirstOrDefault();
if (node != null)
{
txtLoggedIn.Text += "<a href=\"" + node.Url + ".aspx\">" + roles[i] + "</a>" + "<br/>";
}
}
}
string[]roles=Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name);stringzLinkText;for(inti=0;i<roles.Length;i++){if(roles[i]!="Standard"){zLinkText=roles[i].Replace(" ","");//Remove all spaces from the member role to create the linkNodezNode=umbraco.uQuery.GetNodesByName(zLinkText).FirstOrDefault();if(zNode!=null){txtLoggedIn.Text+="<a href=\""+zNode.Url+".aspx\">"+roles[i]+"</a>"+"<br/>";}}}
Get a 'node's URL from it's name (C# UserControl)
Hi Folks,
I'm exactly sure how to word this so if this has already been answered then accept my apologies (!).
I'm using a UserControl to display to a logged in user what Member Groups have assigned to them. For each individual group there is going to be a matching page. So, for instance, if I have a member group called LimitedAccess then there will be a page called LimitedAccess.aspx.
What i'm trying to do is for each Member Group that I'm displaying to a member, I want to create a link that goe's off to the matching page. Originally I took the name of the member group and slapped '.aspx' on the end and all was well. But I've realised that a) this is a rubbish solution and b) this will only work if the matching document lives on a certain level within the content tree.
What I'd like to be able to do is to get the URL of the node by it's name (which I'll know from the member group) and then dynamically build the tags using this URL. The code snippet I'm currently using is below.
Thanks in advance,
Craig
Craig,
If the page exists in the content tree then you can create the link with zLinkText.NiceUrl
so the full thing would be:
Hi Richard,
ZlinkText is just a string though......it doesn't currently relate to a document. I need to relate it to a document and that's what I'm unsure of how to do in UserControl.
Thanks,
Craig
Sorry I thought zLinkText was your node.
Ok you'll have to include some additional logic to ensure it's related but I'd do:
var startNode = new Node(1201); //the node id for the start node
var childNodes = startNode.Children;
foreach(var node in childNodes)
{
<a href=\"" + node.NiceUrl + "\" title=\"" + node.Name + "\"/>" + node.Name + </a>";
}
You'll have to add some logic in to ensure that the user has access to the link you're displaying of course but this is just a way you can get the nodes.
Instead of having the node id you can always register the node in web.config and then call it like
var startNode = Convert.ToInt32(ConfigurationManager.AppSettings["whateverName"]));
Hi again Richard (and thanks for your help again!),
I haven't got the option to create 'new Node(1201)' (Intellisense isn't giving me anything to do with nodes) so I presume that I'm missing a namespace reference somewhere. I'm using
using umbraco.cms.businesslogic.member;
To open up the Member Class but I don't know which one relates to the actual content of the site! All in all I don't know a lot!
Thanks for your patience!
Craig
You know that 1201 is the node of your parent/start node right?
Using Umbraco.NodeFactory is what you need to get that. A tip in VIsual Studio if you get the squiggly red underline, click on it and then press Ctrl+. (as in the dot character), this will bring up a list of available namespaces
Regarding showing which groups a user is a member of I'm not sure there is anything available in the API for that, so you may have to write a stored procedure for that.
The two database tables involved are cmsMember which shows the members and the member id and also cmsMember2MemberGroup whichshows which group(s) that member is related to.
It wouldn't take much to pull that information back in a stored procedure and display it.
But I'm wondering what your link is actually for since the member group isn't a node in the content tree.
Hi Richard,
What I've got is list of Member Groups and in the content of the site there 'pages' (for want of a better term) that are named the same as the Member Groups. ie. There's a Member Group called MyWebsitesSecureUser there somewhere in the content tree there's a page called MyWebsitesSecureUser.aspx. When a member logs in I'm getting all of the member groups that they are a member of displaying them on screen. But what I'm actually trying to do is create a clickable link so the logged in user not only see's the groups that they belong but they can click the link and be taken to the relevant page.
So while I know that somewhere in the content tree there's a document called MyWebsitesSecureUser.aspx I don't know what it's URL is (because it could exist at any level in the tree) so I need to find the page in the tree and then pull it's URL back and create the link.
I was sorta hoping that there'd be something like GetNodeByName(zMyPageName) in much the same way as I get the Member roles by the GetRolesForUser function....
Thanks again :)
Hi Craig,
There is a helper method in uQuery for this: "uQuery.GetNodesByName(string name)". If you are using Umbraco 4.8+ then uQuery is under the "umbraco" namespace, otherwise if you are using an earlier version, download an older version of uComponents (e.g. v3.x, v4.x).
An example code snippet would be:
Good luck!
Cheers, Lee.
Will this pull back the groups that each member is in?
If so then Lee's way is much better :)
Damn you Lee - you evil genius! :D
Absolute legends!!!!
Final bit of code......
Thanks again. Wonderful.
Craig
Nice one
Good to know uQuery can be used in that way - will be handy in future!
is working on a reply...