I am using ASP.NET MVC 3. I am using what essentially came with for free in the Visual Studio project template for an MVC project with the "Internet Application" option. Basically this brings in Forms authentication and provides some basic elements to manage user login and stuff.
I am also using the web profiles stuff with this to store some custom fields. Everything was going great. I use SuperFunProfile
as a wrapper around the Profile
instance to make it easier to get at profile properties.
Until I wanted to set a property of a Profile right away after signing the user up.
The problem I can't solve is that this.Request.RequestContext.HttpContext.Profile
contains the profile for the anonymous user. How can I get a new profile for the user now that he should be signed up and signed in?
public ActionResult SignUp(SignUpModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus = this.MembershipService.CreateUser(model.UserName, model.Password, model.Email);
if (createStatus == MembershipCreateStatus.Success)
{
this.FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
var profile = new SuperFunProfile(this.Request.RequestContext.HttpContext.Profile);
profile.DisplayName = model.UserName;
profile.Save();
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError(string.Empty, AccountValidation.ErrorCodeToString(createStatus));
}
}
I poked around Membership and Web.Profile, but I am not seeing anything that looks like it will get me closer to my goal.
Maybe I should just create a ProfileModel that I store myself into the DB rather than using Web.Profile? I could key that on MembershipUser.ProviderUserKey
which would make it easier to create a ProfileModel at sign up, I suppose.