Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Add a User, then add to a roleAdd a User, then add to a role
Previous
 
Next
New Post
6/29/2009 6:38 PM
 

I've been looking through several examples of how to add a user through code. Almost everyone, and the core, use a function in the UserController called CreateUser, which returns a Membership.UserCreateStatus. This is very helpful for end users if, say, a username already exists, I can display a message. What's not cool about this is that it doesn't return a UserId.

I need to programatically create a user, then add them to a role. Is this impossible with CreateUser? Am I stuck with the AddUser function?

Thoughts?

 
New Post
6/30/2009 3:55 AM
 


We would be very insterest on this topic too.

What we found some time ago, when we needed the same answer, was this topic:

http://www.dotnetnuke.com/Community/Forums/tabid/795/forumid/111/threadid/138898/scope/posts/Default.aspx

On the first page, Will Strohl, uses this:

 Select Case objStatus
          Case UserCreateStatus.Success
               ' add to the BLL membership
               Me.User = DotNetNuke.Entities.Users.UserController.GetUserByName(PortalSettings.PortalId, Me.User.Username, True)
               HttpContext.Current.Session.Add("CreateNewUserID", Me.User.UserID)
               If Me.User.UserID > 0 Then MyNameSpace.Events.UserLogin(Me.User)
          Case Else
               ' something happened
     End Select

So it's something like getting the user that is created, by it's username, that should be unique.

Would this help?

 
New Post
6/30/2009 10:45 AM
 

I came to the same realization that you have to get the user by username after you create the account. This seems like a needless trip back to the database, but unfortunatley it seems like the only way. It sure would be nice if the UserCreateStatus object had the userid.

 

 
New Post
6/30/2009 11:12 AM
 


Totally agree.

Maybe some better coder than me knows how to make some function return the UserID?..

Thanks

 
New Post
8/14/2009 5:58 AM
 

Hey guys.

I was also confused about how to get the userID of the user i just created but found that, after i create the user with the CreateUser method, the userInfo object actually contains the userID.

 

Here's a piece of my code, note the red marked text;    


UserInfo userInfo = new UserInfo();

userInfo.PortalID = 0;
userInfo.Username = username;
userInfo.FirstName = firstname;
userInfo.LastName = lastname;
userInfo.DisplayName = username;
userInfo.Email = email;
userInfo.Membership.Approved = true;
userInfo.Membership.Password = password;

DotNetNuke.Security.Membership.UserCreateStatus userCreateStatus = CreateUser(userInfo);

if (userCreateStatus == DotNetNuke.Security.Membership.UserCreateStatus.Success)
   {
        response = "Success! {" + userInfo.UserID.ToString() +" }"; // <- correct user ID retrieved here!

   }

protected DotNetNuke.Security.Membership.UserCreateStatus CreateUser(UserInfo objUserInfo)
   {         
       return UserController.CreateUser(ref objUserInfo);
   }

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Add a User, then add to a roleAdd a User, then add to a role


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out