I'm using the Membership.CreateUser method to register members with my site. But I cannot see how to set the "Name" property MemberType's have by default.
I'm probably missing something easy but I can't think what it is :(
I'm not sure what you mean, but if your issue is that you cannot pass the MemberType information for creating the user, this must in fact be done in the declaration of your membership provider in your web.config file.
When you create a member in the admin, you have to enter name, email, user name and password. When people register with the site themselves I just want them to enter name, email and password and to use email as the user name. I've created a user control to do this and use the following snippet of code to create the member.
MembershipUser member = Membership.CreateUser(Email.Text, Password.Text, Email.Text); Roles.AddUserToRole(member.UserName, "Candidates");
The problem is that sets name as well as user name to the email address where as I only want user name to be the email and name set to whatever the user entered.
Thanks for the explainations, it is indeed a little more clear like this ;-)
Well, my best guess is that you will have to use the Umbraco User class to do that. So, after you have created your member, you can get his/her Id (which is of type int) by casting the member.ProviderUserKey.
Then you can use that Id to load the Umbraco user, and I guess that from there you will be able to change the name back to whatever you wanted.
using umbraco.cms.businesslogic.member; ...
MembershipUser member = Membership.CreateUser(Email.Text, Password.Text, Email.Text); Roles.AddUserToRole(member.UserName, "Candidates"); Member m = new Member((int)member.ProviderUserKey); // Umbraco Member class ...
Note: I'm not sure you can change the name afterwards (or at least that it will reflect in the members tree), so if changing the name does not work, then I would do the other way around: first create the user with the name he/she entered, and then change the login and set it to the email address.
You code snippet will work. I only suggest that you check if the member m exists after you created the object and before you assigne the Text Property. Could be that someone canceled the member create process, via events and then you will get weird errors.
Membership.CreateUser setting Name property
I'm using the Membership.CreateUser method to register members with my site. But I cannot see how to set the "Name" property MemberType's have by default.
I'm probably missing something easy but I can't think what it is :(
Does the silence mean it isn't actually possible and I wasn't just missing something after all.
Hi suzyb,
I'm not sure what you mean, but if your issue is that you cannot pass the MemberType information for creating the user, this must in fact be done in the declaration of your membership provider in your web.config file.
You can find more info about this at this wiki, page : our.umbraco.org/.../umbracomembershipprovider-properties
Basically, your web.config definition will look something like this(check the defaultMemberTypeAlias attribute):
Hope this helps.
Cheers,
Michael
I'm rubbish at explaining things, sorry :/
When you create a member in the admin, you have to enter name, email, user name and password. When people register with the site themselves I just want them to enter name, email and password and to use email as the user name. I've created a user control to do this and use the following snippet of code to create the member.
MembershipUser member = Membership.CreateUser(Email.Text, Password.Text, Email.Text);
Roles.AddUserToRole(member.UserName, "Candidates");
The problem is that sets name as well as user name to the email address where as I only want user name to be the email and name set to whatever the user entered.
Hi suzyb,
Thanks for the explainations, it is indeed a little more clear like this ;-)
Well, my best guess is that you will have to use the Umbraco User class to do that. So, after you have created your member, you can get his/her Id (which is of type int) by casting the member.ProviderUserKey.
Then you can use that Id to load the Umbraco user, and I guess that from there you will be able to change the name back to whatever you wanted.
Note: I'm not sure you can change the name afterwards (or at least that it will reflect in the members tree), so if changing the name does not work, then I would do the other way around: first create the user with the name he/she entered, and then change the login and set it to the email address.
Cheers,
Michael.
Hi Michael,
You code snippet will work. I only suggest that you check if the member m exists after you created the object and before you assigne the Text Property. Could be that someone canceled the member create process, via events and then you will get weird errors.
Cheers,
Richard
Hi Richard,
Thanks, you are right, it is indeed best to test that m gets assigned to something prior to doing any operation on it.
Cheers,
Michael.
Thanks Michael that seems to have worked. I create the member with the user name set to the name then change it afterwards.
Glad you got it sorted out :-)
Cheers,
Michael.
is working on a reply...