我正在嘗試註冊一個新用戶,同時也知道如何獲得新的用戶ID,所以我可以開始創建我自己的用戶表,並將用戶ID映射到asp.net成員資格用戶表。ASP.NET MVC成員,獲取新的用戶ID
下面是我的代碼:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Register(string userName, string email, string position, string password, string confirmPassword)
{
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
ViewData["position"] = new SelectList(GetDeveloperPositionList());
if (ValidateRegistration(userName, email, position, password, confirmPassword))
{
// Attempt to register the user
MembershipCreateStatus createStatus = MembershipService.CreateUser(userName, password, email);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuth.SignIn(userName, false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View();
}
我做了一些研究,許多網站告訴我使用Membership.GetUser()ProviderUserKey。但是這會引發一個錯誤,因爲Membership是NULL。我把這行代碼放在上面「return RedirectToAction(」Index「,」Home「);」在if語句中。
請能有人告訴我這個...
在此先感謝