如何获取当前用户主体

Jai*_*der 3 asp.net windows-authentication userprincipal groupprincipal

我想使用 Windows 身份验证并获取用户信息,例如名字、姓氏等。我UserPrincipal.Current在 IIS 中使用,但出现异常,但 IIS Express 看起来不错。

Jai*_*der 5

我通过使用查找方法解决了:

var domain = new PrincipalContext(ContextType.Domain);
var currentUser = UserPrincipal.FindByIdentity(domain, User.Identity.Name);
Run Code Online (Sandbox Code Playgroud)