Getting Active Directory Info when using Windows Authentication?

后端 未结 4 421
温柔的废话
温柔的废话 2021-01-31 06:25

I am using Windows authentication on my asp.net MVC 3 app. Is there any way possible to get the users information out of active directory?

I know I can user User.Name.Id

4条回答
  •  不知归路
    2021-01-31 06:51

    If your code is running under the context of the user that you need information for, it gets even lighter (i.e. Windows Authentication):

    //Must reference System.DirectoryServices.AccountManagement
    var user = UserPrincipal.Current;
    
    var firstName = user.GivenName;
    var lastName = user.Surname;
    

提交回复
热议问题