我想在我的 razor View 页面中获取当前经过身份验证的用户名,因此我使用
if (User.Identity.IsAuthenticated)
{
<p>Name is @User.Identity.Name</p>
}
但@User.Identity.Name始终显示用户的ID。
最佳答案
试试这个(MVC):
@{ var userName = System.Web.HttpContext.Current.User.Identity.Name; }
关于asp.net-mvc-4 - 在 Razor 中获取当前用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26882762/