Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

You can use the regular ASP.NET membership functions to create and manage users. Look inside N2.Edit.Membership.Edit and you will find that it is as simple as: 

To do this...Use this code...
Add a user to a role
Roles.AddUserToRole(username, rolename); 
Remove a user from a role
Roles.RemoveUserFromRole(username, rolename);
Save changes to a user
System.Web.Security.Membership.UpdateUser(username);
Create a new user 
Delete a user 

How does it work?

If you look in web.config you will see that everything membership-related is actually driven by N2.Security.ContentMembershipProvider by default. 

Code Block
languagehtml/xml
<providers>
	<add passwordFormat="Hashed" 
		name="ContentMembershipProvider" 
		type="N2.Security.ContentMembershipProvider, N2.Management" />
</providers>

...

All manipulation with users are done with ItemBridge...

Code Block
languagec#
ItemBridge bridge = N2.Context.Current.Resolve<ItemBridge>();

Now you can create new user with custom profile and populate his custom properties...

Code Block
languagec#
UserProfile newUser = (UserProfile)bridge.CreateUser("John Doe", "Password", "office@doe.com", "", "", true, null) as UserProfile;
newUser.Age = "33";
bridge.Save(newUser);

Or find existing ones and update them...

Code Block
languagec#
UserList users = bridge.GetUserContainer(false);
UserProfile user = users.Children.OfType<UserProfile>().Where(u => u.Email == "john@doe.com").FirstOrDefault();
user.Age = "34";
bridge.Save(user);

...