How I can get my first name last name with c# in my system (logging in windows with Active Directory username and pass)?
Is it possible to do that without going to the AD?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re using .Net 3.0 or higher, there’s a lovely library that makes this practically write itself.
System.DirectoryServices.AccountManagementhas aUserPrincipalobject that gets exactly what you are looking for and you don’t have to mess with LDAP or drop to system calls to do it. Here’s all it’d take:Note: you don’t actually need the principal if you already have the username, but if you’re running under the users context, it’s just as easy to pull it from there.