简体   繁体   English

如何使用Active Directory中的信息填充文本字段?

[英]How do I populate text fields with information from Active Directory?

I would like to populate some read only text fields with information from Active Directory, for example name and email address for the user who is currently logged on. 我想用Active Directory中的信息填充一些只读文本字段,例如当前登录用户的名称和电子邮件地址。

I am using .NET Core 2.2 and getting conflicting information as to whether this is natively supported, for example, the Microsoft documentation says it isn't but the GitHub repository indicates it is. 我正在使用.NET Core 2.2并获得有关是否本机支持的相互矛盾的信息,例如,Microsoft文档说它不是,但GitHub存储库表明它是。 Some information indicates it's now native support, some says it's done with a compatibility library. 一些信息表明它现在是原生支持,有些人说这是用兼容性库完成的。

What should I use to perform such as task? 我应该用什么来执行任务?

Thanks, 谢谢,

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string user = userName.Split('\\')[1];
string domain = userName.Split('\\')[0];

For what I needed, the following code is what I was after, a number of other fields can be used too: 对于我所需要的,以下代码就是我所追求的,也可以使用其他许多字段:

public static String Email = UserPrincipal.Current.EmailAddress;

I can then reference these in my Razor Pages. 然后我可以在我的Razor页面中引用它们。

This was using System.DirectoryServices.AccountManagement; 这是使用System.DirectoryServices.AccountManagement; so it looks as though System.DirectoryServices is natively supported in .NET Core, or at least in the context I needed. 所以看起来.NET .NET中本身支持System.DirectoryServices ,或者至少在我需要的上下文中。 I'll need to do some more digging. 我需要做更多的挖掘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM