I would like to create user in my user table when new user have just registered to ASP.NET MVC application (I use the default ASP.NET MVC logging system – Membership. I want to get the new registered user’s guid and create user in my database which will have the same guid and keep there different data like name surname etc. How can I do it? How can I just get the registered person ID? I was trying to do it in
public ActionResult Register(RegisterModel model) function in AccountController
but I do not know how to get the just registered user’s guid this is not working:
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
if (createStatus == MembershipCreateStatus.Success)
{
FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
//string guid = Helpers.getLoggedUserGuid(); //return null
//if (Request.IsAuthenticated) { } // return false
//if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) {} // return false
//Membership.getUser() // return null
//The most funny is that after this redirection below the user is logged in - I do not understand it
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View(model);
}
Is any possibility to get this guid in this function? (I know that I can get userName and so on but I can not understand why I can not get this guid)
You can get Guid from
MembershipUser:MSDN: