![](/img/trans.png)
[英]C# - Windows authentication - How to get from HttpContext user's Full doMain name (FQDN)
[英]how to find user full name in domain from service running with system account in c#
我有使用系统帐户运行的服务,我在下面的代码中找到了该代码,该代码在使用用户帐户运行时给出正确的用户名,而在使用系统帐户运行时给出错误。 当系统帐户运行服务时,有人可以帮助您查看登录的用户全名吗?
private static string GetFullName()
{
try
{
DirectoryEntry de = new DirectoryEntry("WinNT://" + Environment.UserDomainName + "/" + Environment.UserName);
return de.Properties["fullName"].Value.ToString();
}
catch { return null; }
}
答:我不是通过使用Environment.UserDomainName +“ /” + Environment.UserName而是手动传递了域和用户名,此问题已解决。
您可以分别获得名字和姓氏,然后可以如下所示返回,
private static string GetFullName()
{
try
{
DirectoryEntry de = new DirectoryEntry("WinNT://" + Environment.UserDomainName + "/" + Environment.UserName);
return de.Properties["FullName"].Value.ToString();
}
catch { return null; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.