问题描述
我只是尝试使用带有自定义UserStore的Asp Core Identity更新现有的用户。
某些代码上下文:
(自定义应用程序用户)
public class ApplicationUser {
public string web_user_soc_code { get; set; }
public string web_user_id { get; set; }
public string web_user_name { get; set; }
public string web_user_normalized_name { get; set; }
public string web_user_password { get; set; }
public DateTime? web_user_date_crea { get; set; }
public List<ApplicationRole> roles { get; set; }
}
(自定义UserStore)
(我的控制器中的更新方法)
[HttpPut]
[Authorize(Roles = "Administrateur")]
public JsonResult UpdateUser(string id,string username) {
ApplicationUser user = userManager.FindByIdAsync(id).Result;
if (user == null || user.web_user_id == null) {
return Json(new { success = false,responseText = "Imposible de trouver l'utilisateur demandé" });
}
// Replacing with the new username
user.web_user_name = username;
// Updating... Throws error "Username xxx already exists"
IdentityResult result = userManager.UpdateAsync(user).Result;
return Json(result == IdentityResult.Success ?
new { success = true,responseText = "L'utilisateur a été modifié avec succès" } :
new { success = false,responseText = result.Errors.FirstOrDefault()?.Description });
}
所以我要做的就是更新他的用户名,但是当我打电话给userManager.UpdateAsync(user)
时,我出现一个错误,说该用户名已经存在(当然不存在)...
我已经看到使用userManager.SetUserNameAsync(...)
时会引发相同的错误。
所以我绝对不知道它可能来自哪里/我做错了什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)