如何在ASP.NET MVC中获取新注册用户的userId?

时间:2017-12-05 06:30:20

标签: c# asp.net asp.net-mvc asp.net-identity

我试图将userId存储在AspNetUsers表中,并在注册过程中将其存储在我的Student表中。

如何从userId表中获取新创建的用户{<1}}(不是登录用户),并将其存储在单独的表格中注册过程中?

我的控制器:

AspnetUsers

2 个答案:

答案 0 :(得分:0)

如果您创建了用户,则会自动为您创建ID。

 var objNewAdminUser = new ApplicationUser { UserName = UserName, Email = Email};
 var userId = objNewAdminUser.Id //18479b0a-17cd-4a76-9e9e-d90a8480617b

答案 1 :(得分:0)

you can try this

if(AdminUserCreateResult.Succeeded == true)
{
//Get Details of currently registered User
    var RegisteredUser= SignInManager.UserManager.FindByEmail(Email);
//Extract userid from user Details.
    var userid=RegisteredUser.Id;
//this will give you the ID stored in aspnetusers of currentUser
}