Personally, I would recommend against using the SQL Profile Provider (which is what you are using). Nothing has changed with profiles since MVC2 (or, for that matter, since it was introduced in webforms with .NET 2.0).
The reason is this: Profile data is stored as XML in the database, which makes it very difficult to use profile data outside of your app (meaning in a pure SQL query).
You're probably much better off creating profile fields in your database directly. This way you know which table / column the data is coming from, and can create views if you need to. Otherwise, you would have to parse a table column's XML to extract the profile data (which is what the ProfileCommon does in .NET).
Reply to comments
First of all, I was wrong about the property name. It is ProviderUserKey, not ProviderKey. However unless you want to store profile properties for anonymous users, you could just as easily use MembershipUser.UserName as your FK value, since it will also be unique.
[HttpPost]
public ActionResult Register(RegisterModel model)
{
MembershipCreateStatus createStatus;
var membershipUser = Membership.CreateUser(model.UserName, model.Password,
model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
var providerKeyObject = membershipUser.ProviderUserKey;
var providerKeyGuid = (Guid)membershipUser.ProviderUserKey;
// Use providerKeyGuid as a foreign key when inserting into a profile
// table. You don't need a real db-level FK relationship between
// your profile table and the aspnet_Users table. You can lookup this
// Guid at any time by just getting the ProviderUserKey property of the
// MembershipUser, casting it to a Guid, and executing your SQL.
// Example using EF / DbContext
using (var db = new MyDbContext())
{
var profile = new MyProfileEntity
{
UserId = providerKeyGuid, // assumes this property is a Guid
FirstName = model.FirstName,
LastName = model.LastName,
};
db.Set<MyProfileEntity>().Add(profile);
db.SaveChanges();
}
// you could get the profile back out like this
using (var db = new MyDbContext())
{
var profile = db.Set<MyProfileEntity>().SingleOrDefault(p =>
p.UserId == (Guid)membershipUser.ProviderUserKey);
}
FormsAuthentication.SetAuthCookie(membershipUser.UserName, false);
return RedirectToAction("Index", "Home");
}
return View(model);
}
Here is an example using the UserName instead of the ProviderUserKey. I would recommend this approach if you are not storing profile info for anonymous users:
[HttpPost]
public ActionResult Register(RegisterModel model)
{
MembershipCreateStatus createStatus;
var membershipUser = Membership.CreateUser(model.UserName, model.Password,
model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
// Example using EF / DbContext
using (var db = new MyDbContext())
{
var profile = new MyProfileEntity
{
// assumes this property is a string, not a Guid
UserId = membershipUser.UserName,
FirstName = model.FirstName,
LastName = model.LastName,
};
db.Set<MyProfileEntity>().Add(profile);
db.SaveChanges();
}
// you could get the profile back out like this, but only after the
// auth cookie is written (it populates User.Identity.Name)
using (var db = new MyDbContext())
{
var profile = db.Set<MyProfileEntity>().SingleOrDefault(p =>
p.UserId == User.Identity.Name);
}
FormsAuthentication.SetAuthCookie(membershipUser.UserName, false);
return RedirectToAction("Index", "Home");
}
return View(model);
}