我如何获取从登录页面登录的用户的名称 [英] how can i get the name of the user who logged in from login page

查看:95
本文介绍了我如何获取从登录页面登录的用户的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想获取从我的登录页面登录的用户的名称.我使用LoginName控件,但它显示Windows用户名.




i want to get the name of the user who is logged in from my login page. I use LoginName control but it displays the name of my windows user name

推荐答案

WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;
// or, if you're in Asp.Net with windows authentication you can use:
// WindowsPrincipal principal = (WindowsPrincipal)User;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain))
{
    UserPrincipal up = UserPrincipal.FindByIdentity(pc, principal.Identity.Name);
    return up.DisplayName;
    // or return up.GivenName + " " + up.Surname;
}


尝试
User.Identity.Name



如下所示



as given below

if (User.Identity.IsAuthenticated)
    LabelUName.Text = User.Identity.Name;
else
    LabelUName.Text = "No user identity available.";


简单的方法是使用会话.


为用户名创建会话
例如:session ["UserName"]


您还可以创建多个会话,并在当前项目的所有页面中使用.



接受如果回答.是正确的.
Simple way is use session.


create session for username
for ex: session["UserName"]


you can also create multiple session, and use in all page of current project.



accept if ans. is right.


这篇关于我如何获取从登录页面登录的用户的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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