身份验证提供程序返回错误。请验证您的输入,然后重试

时间:2013-07-31 08:54:03

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

编辑:原来这是由于语言和字符中的字符,例如i / u等。

[HttpPost]  
        /*[Authorize(Roles = "admin")]*/
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var users = _userdb.UserProfiles.Where(x => x.UserName == model.UserName); 
                if (users.Any())
                {
                    ModelState.AddModelError("Error", "Username Already Exists.");
                    return View(model);
                }

                try
                {
                    if (model.IsAdmin == false)
                    {
                        WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new
                        {
                            CellPhone = model.CellPhone,
                            Email = model.Email,
                            SocialNo = model.SocialNo,
                            Department_Id = model.DepartmentId
                        });


                    }
                    else
                    {
                        WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new
                        {
                            CellPhone = model.CellPhone,
                            Email = model.Email,
                            SocialNo  = model.SocialNo ,
                            Department_Id = 9999
                        });

                        Roles.AddUserToRole(model.UserName, "admin"); 
                    }

                    return RedirectToAction("Departments", "Index");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

我收到此错误,这实际上没有用。我只是想注册一个用户。

为什么我收到此错误?任何的想法?

请注意,UserProfile正在获取数据,但不是会员表。

0 个答案:

没有答案