I am using Membership provider
to deal with user registration and logging to the website. This Membership provider
is part of a package comes through:
Install-Package Microsoft.AspNet.Providers
I have two ASPX
pages one has a CreateUserWizard
control and the other has a Login
control. The registration and logging is working correctly.
I have defined Profile
properties in the web.config file:
<profile defaultProvider="DefaultProfileProvider">
<properties>
<add name="Id" type="System.Guid" />
<add name="UserName"/>
</properties>
What I am trying to is to be able to take the UserId
and UserName
values on registration of the user, and store them to Profile.Id
and Profile.UserName
respectively.
How to customize the CreateUserWizard
to achieve this?.
My try:
When you show CreateUserWizard
on the browser. You can see a button named "Create User", so I thought it is a good place to extend on and add code to take the required values. So I clicked the small arrow on CreateUserWizard
and choose Customize Create User Setup
, but the editable template doesn't include the corresponding button of "Create User".
So what is the possible way to achieve that?
In the aspx file under events of the CreateUserWizard control, there is a "createdUser" event you can create.
In the cs file of the CreateUser function put in:
MembershipUser newUser = Membership.GetUser(NewUserWizard.UserName);
Guid newUserId = (Guid)newUser.ProviderUserKey;
newUser.UserName will give you the UserName, and NewUserId will give you the id. At that point you should have what you need.