如何显示显示名称而不是用户名c#
我对web开发和.NET也是新手。我有一个用C#编写的ASP.NET网站。如何使用会话显示当前用户的全名而不是用户名?请帮帮我。这是代码 登录页面后面的代码:-如何显示显示名称而不是用户名c#,c#,C#,我对web开发和.NET也是新手。我有一个用C#编写的ASP.NET网站。如何使用会话显示当前用户的全名而不是用户名?请帮帮我。这是代码 登录页面后面的代码:- System.Security.Principal.WindowsPrincipal username = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal; string userName = u
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();
}
用这个,它就行了。我假设您正在使用windows身份验证。如果它对您有效,请将其标记为答案,以便其他人看到它并从中获得帮助
using System.DirectoryServices.AccountManagement;
string name = UserPrincipal.Current.GivenName + " " + UserPrincipal.Current.Surname;
您必须安装Windows.Security.NuGet,然后将其写入代码: 私有字符串SessionUsernameText=System.Security.Principal.WindowsIdentity.GetCurrent().Name