0
我想在新用戶剛剛註冊到ASP.NET MVC應用程序時在我的用戶表中創建用戶(我使用默認的ASP.NET MVC日誌記錄系統 - Membership。我想獲得新的註冊用戶的GUID,並在我的數據庫中創建用戶,這將有相同的GUID,並保留不同的數據,如姓氏等。我該怎麼辦?我怎麼才能得到註冊人的ID?我試圖在ASP.NET MVC2 + Membership
public ActionResult Register(RegisterModel model) function in AccountController
,但我不知道如何讓剛剛註冊用戶的GUID這是行不通的:
[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);
}
有沒有可能在這個函數中得到這個guid? (我知道我可以獲取用戶名和等,但我不明白爲什麼我不能得到這個GUID)