I am using this in c# MVC. I am creating a registration screen for the user with the following fields
UserName,Password,Role,Location
The Role can be either “Admin” or “User”.
The Location, it can be either “New York” or “Chicago”.
Once the user fills out the form and clicks on Submit, I have the following code:
.....
.....
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, null, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
Roles.AddUserToRole(model.UserName, model.Role);
return RedirectToAction("Index", "Home");
}
I have taken care of Creating the user and also giving that user a role as you can see above. I am not sure how to tie the Location with the User and Role though. What aspnet table would Location go into? Is there a method that already handles something like this?
1: You can use built-in ASP.NET Profile to store custom user information
2: To be more customized and having more control over data manipulation, you will have to create a separate table to store the additional user details. Something along these lines.
3: IF you think there’s only going to be ONLY ONE FIELD FOREVER, a weirdest way is to use Comment property of MembershipUser. Though not sure how best it fit your needs.