我无法使用WebSecurity.Login登录,我将WebSecurity.CurrentUserId作为-1。

时间:2015-08-18 18:03:45

标签: model-view-controller login

我正在尝试注册用户,并为未注册的用户执行相同的操作。请在下面查看我的代码中有问题的部分。我在这里得到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 

0 个答案:

没有答案