Change username in MVC 5

Fran_gg7 picture Fran_gg7 · Feb 13, 2014 · Viewed 8.1k times · Source

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

It is possible for users to change the username?

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

Regrads,

Fran.

Answer

Keith B picture Keith B · Apr 15, 2015

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);

This method works successfully for me