编辑:原来这是由于语言和字符中的字符,例如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
正在获取数据,但不是会员表。