Model view controller 我能';t使用WebSecurity.login登录,我得到的WebSecurity.CurrentUserId为-1。

Model view controller 我能';t使用WebSecurity.login登录,我得到的WebSecurity.CurrentUserId为-1。,model-view-controller,login,Model View Controller,Login,我正在尝试注册一个用户,并对未注册的用户执行相同的操作。请参阅下面我代码中有问题的部分。我在这里得到WebSecurity.CurrentUserId为-1。因此,我无法找到用户并将用户信息添加到订单中。这里出了什么问题。它应该是新注册用户的Id。谢谢你的帮助 WebSecurity.CreateUserAndAccount(UpperEmail, user.Password, new { user.Password, user.PasswordConfirm, user.Email, user

我正在尝试注册一个用户,并对未注册的用户执行相同的操作。请参阅下面我代码中有问题的部分。我在这里得到WebSecurity.CurrentUserId为-1。因此,我无法找到用户并将用户信息添加到订单中。这里出了什么问题。它应该是新注册用户的Id。谢谢你的帮助

WebSecurity.CreateUserAndAccount(UpperEmail, user.Password, new { user.Password, user.PasswordConfirm, user.Email, user.Name }, false);

                        int userId = db.Users.FirstOrDefault(u => u.Email == user.Email).Id;
                        if (!Roles.RoleExists("User"))
                            Roles.CreateRole("User");
                        Roles.AddUserToRole(UpperEmail, "User");
                        WebSecurity.Login(UpperEmail, user.Password);

                        neworder.user = db.Users.Find(WebSecurity.CurrentUserId);
                        neworder.UserId = WebSecurity.CurrentUserId;
                        neworder.PaymentStatus = PaymentStatus.Onaylandi;I