2016-07-21 134 views
-1

我是网络开发和.NET的新手。我有一个使用C#编写的ASP.NET网站。我应该如何显示当前用户的全名而不是使用会话的用户名?请帮帮我。这是代码。后面的登录页面如何显示显示名称而不是用户名c#

代码: -

System.Security.Principal.WindowsPrincipal username = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal; 
    string userName = username.Identity.Name; 

    if (username.Identity.IsAuthenticated) 
    { 
     Session["logged"] = userName; 
     agentname.Text = Session["logged"].ToString(); 
    } 
    else 
    { 
     agentname.Text = "You are not loggd in please logine first "; 
    } 
    if (Session["logged"] == null) 
    { 
     agentname.Text = "You are not loggd in please login first "; 
    } 
    else 
    { 
     agentname.Text = Session["logged"].ToString(); 
    } 

回答

1

利用这一点,它的工作原理。我假设你正在使用Windows身份验证。如果它适合你,请将其标记为答案,以便其他人可以看到并从中获得帮助。

using System.DirectoryServices.AccountManagement; 

    string name = UserPrincipal.Current.GivenName + " " + UserPrincipal.Current.Surname; 
相关问题