In a Asp.net Core project, I´m using the code below to change user name and email. But the property "User" in the controller does not update, just after logoff.
obs.: This "User" property is already defined by the framework in controller bases class, and it is a "ClaimsPrincipal" type.
Controller
public async Task<IActionResult> Create(EditViewModel viewModel)
{
if (ModelState.IsValid)
{
var model = await _userManager.FindByIdAsync(CurrentUser.Id);
model.UserName = viewModel.UserName;
model.Email = viewModel.Email;
await _userManager.UpdateAsync(model);
//THIS ONE STILL HAS OLD VALUES ==============================
Console.WriteLine(_userManager.GetUserName(User));
//THIS ONE HAS NEWER VALUES ==================================
model = await _userManager.FindByIdAsync(CurrentUser.Id);
Console.WriteLine(model.UserName);
...
I´m using this "User" property in my views, to display user informations, like this:
View
@inject UserManager<ApplicationUser> UserManager
...
<p>Hello: @UserManager.GetUserName(User)</p>