如何获取当前用户主体 [英] How to Get Current User Principal
本文介绍了如何获取当前用户主体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Windows身份验证和获取用户信息,如给定名称,姓氏等。
我在IIS中使用 UserPrincipal.Current
键,我得到了一个例外,但IIS前preSS看起来不错。
I want to use Windows Authentication and get User info such as Givenname, Surname, etc.
I used UserPrincipal.Current
in IIS and I got an exception, but IIS express looks fine.
推荐答案
我用查找方法解决:
var domain = new PrincipalContext(ContextType.Domain);
var currentUser = UserPrincipal.FindByIdentity(domain, User.Identity.Name);
这篇关于如何获取当前用户主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文