Asp.net 如何获取当前用户主体

Asp.net 如何获取当前用户主体,asp.net,windows-authentication,userprincipal,groupprincipal,Asp.net,Windows Authentication,Userprincipal,Groupprincipal,我想使用Windows身份验证并获取用户信息,如Givenname、姓氏等。 我在IIS中使用了UserPrincipal.Current,我得到了一个异常,但IIS express看起来很好。我使用查找方法解决了这个问题: var domain = new PrincipalContext(ContextType.Domain); var currentUser = UserPrincipal.FindByIdentity(domain, User.Identity.Name);

我想使用Windows身份验证并获取用户信息,如Givenname、姓氏等。
我在IIS中使用了
UserPrincipal.Current
,我得到了一个异常,但IIS express看起来很好。

我使用查找方法解决了这个问题:

var domain = new PrincipalContext(ContextType.Domain);
var currentUser = UserPrincipal.FindByIdentity(domain, User.Identity.Name);