用户名更改后,在导航栏中刷新用户名(使用Asp.Net,MVC和C#) [英] Refresh user name in navbar after username has changed (Using Asp.Net, MVC and C#)

查看:112
本文介绍了用户名更改后,在导航栏中刷新用户名(使用Asp.Net,MVC和C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用户登录时更改其用户名或此处的用户名后,我正在尝试在导航栏中更新用户名(使用ASP.NET,MVC,C#).因此显示了用户名,但是更改了用户名导航栏中仍会显示旧的用户名,直到该用户注销并再次登录.

I am trying to update the user name in the navbar (using ASP.NET, MVC, C#) after a user has changed his or here user name when signed in. So the user name is shown, but when it's changed the old user name is still being displayed in the navbar until the user loges out and in again.

有人知道如何以一种不错的方式在导航栏中显示新用户名吗?

Dose any one know how to display the new user name in the navbar in a nice way?

这是导航栏外观的简短版本:

This is a short version of how the navbar looks like:

<nav class="navbar navbar-default navbar-fixed-top">
@if (Request.IsAuthenticated)
{
    @Html.AntiForgeryToken()
    <a href='@Url.Action("Index", "Manage")'>@User.Identity.GetUserName()</a>
}
</nav>

以下是新用户名/电子邮件的更新方式的简短版本:

And below is the short version for how the new user name / e-mail is updated:

aspUser.UserName = model.Email;
aspUser.Email = model.Email;
var result = await UserManager.UpdateAsync(aspUser);

if (result.Succeeded)
// Want to update the navbar, maybe here?

(电子邮件和用户名在此应用程序中是同一件事)

(e-mail and user name is the same thing in this application)

推荐答案

要在更改用户名后自动登录用户,您需要根据我对问题的评论运行SingInAsync方法. await SignInManager.SignInAsync(aspUser, true, true);

In order to sign in user automatically after change of username you need to run SingInAsync method as per my comments on your question. await SignInManager.SignInAsync(aspUser, true, true);

这篇关于用户名更改后,在导航栏中刷新用户名(使用Asp.Net,MVC和C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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