在MVC 5中更改用户名 [英] Change username in MVC 5

查看:116
本文介绍了在MVC 5中更改用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET MVC5和Identity 2.0(测试版).

I am using ASP.NET MVC5 and Identity 2.0 (beta).

用户可以更改用户名吗?

It is possible for users to change the username?

我正在尝试使用UserManager.UpdateAsync方法引发异常.

I am trying using UserManager.UpdateAsync method throws an exception.

奖励,

Fran.

推荐答案

是的,可以使用UpdateAsync方法,但是您需要确保同时更新电子邮件和用户名字段.

Yes it is possible using the UpdateAsync method but you need to ensure that you update both the email and username fields.

var user = userManager.FindById(userId);
user.Email = email;
user.UserName = email;

var updateResult = await userManager.UpdateAsync(user);

此方法对我来说成功

这篇关于在MVC 5中更改用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆