Search code examples
c#asp.netasp.net-membershipmembership-provider

how to add custom parameters to membership create user wizard?


I am really confused right now. Ive read some solutions to this problem, but every single one is different.... some people say that web applications projects and web site projects need different solutions.

What I have in thoughts:

I have a web application project

I created a table UserProfile in that table where I store additional columns like a link to an image.

My problem right now is that when I call RegisterUser_CreatedUser on submit, I can't find any way to get Guid of the newly created user :

 protected void RegisterUser_CreatedUser(object sender, EventArgs e)
 {
      FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

      TextBox ImageUrl = RegisterUserWizardStep.ContentTemplateContainer.FindControl("ImageUrl") as TextBox;

      UserProfile.SaveNewProfileInformation("place for new created user guid", ImageUrl.Text);

      string continueUrl = RegisterUser.ContinueDestinationPageUrl;

      if (!OpenAuth.IsLocalUrl(continueUrl))
      {
         continueUrl = "~/";
      }

      Response.Redirect(continueUrl);
}

How do I get the guid of new created user? and am i on the right track at all to solve this problem?


Solution

  • You need to get the created user with the UserName

    {
        FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);
    
        //If user is created, get it by UserName
        MembershipUser createdUser = Membership.GetUser(RegisterUser.UserName);       
        Guid userID = new Guid(createdUser.ProviderUserKey.ToString());
    
        TextBox ImageUrl = RegisterUserWizardStep.ContentTemplateContainer.FindControl("ImageUrl") as TextBox;
    
        //Use the userID from the above code
        UserProfile.SaveNewProfileInformation(userID, ImageUrl.Text);
    }