【发布时间】:2019-10-14 10:01:52
【问题描述】:
我曾经使用 UserPrincipal 类来检索用户的活动目录信息,特别是 EmployeeId(不是用户名,我们通常不使用它来将员工与 sql 中的特定数据点联系起来)。但是,在 .net 核心中,该类不存在,而且我对 .net 核心还是很陌生,所以我不确定它的许多功能在 Intranet 设置中如何工作。我知道很多人可能无法使用跨平台的 asp.net 核心和其他不知道活动目录的服务器类型。
以下是我在常规 asp.net 环境中用于获取员工 ID 的代码。
var userContext = System.Web.HttpContext.Current;
PrincipalContext pcxt = new PrincipalContext(ContextType.Domain, "mydomain.com");
UserPrincipal uPrincipal = UserPrincipal.FindByIdentity(pcxt, IdentityType.SamAccountName, userContext.User.Identity.Name);
return uPrincipal.EmployeeId;
如果有的话,我可以使用什么样的代码来获取相同的信息?没有第三方库可以吗?看来 IIS 服务器可能会通过声明传输我需要的某种信息?我曾尝试进行研究,但每件事都会让我走上更多的研究道路,我不知道从哪里开始。
【问题讨论】:
标签: c# asp.net-core