Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Security / December 2006

Tip: Looking for answers? Try searching our database.

How to retrieve the domain name for an AD user object?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pucca - 20 Dec 2006 02:06 GMT
Hi, I'm using VS2003 C#, .net 2.0 running on Windows Server 2000.  

I have a User's SID in SDDL format and also a DIRECTORYENTRY object
representing this user object.  How can I retrieve the name of the domain
that this user object belongs to?  
Signature

Thanks.

Joe Kaplan - 20 Dec 2006 02:52 GMT
Probably the easiest way is create a SecurityIdentifier object and convert
it to an NTAccount with the Translate method.  You could also get the prefix
of the SID and query AD to find the domainDNS object that has that SID.

Joe K.

Signature

Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--

> Hi, I'm using VS2003 C#, .net 2.0 running on Windows Server 2000.
>
> I have a User's SID in SDDL format and also a DIRECTORYENTRY object
> representing this user object.  How can I retrieve the name of the domain
> that this user object belongs to?
Pucca - 20 Dec 2006 03:25 GMT
Hi Joe,

This is what I got so far.  I need to get the domain name in a string.  How
can I do that from here?  thank you.

//sid = S-1-5-21-1993962763-879983540-725345543-500
           SecurityIdentifier sdSID = new SecurityIdentifier(sid);
           string domainSid = sdSID.AccountDomainSid.Value.ToString();
           SecurityIdentifier domain = new SecurityIdentifier(domainSid);

Signature

Thanks.

> Probably the easiest way is create a SecurityIdentifier object and convert
> it to an NTAccount with the Translate method.  You could also get the prefix
[quoted text clipped - 7 lines]
> > representing this user object.  How can I retrieve the name of the domain
> > that this user object belongs to?
Joe Kaplan - 20 Dec 2006 05:02 GMT
NTAccount account = domain.Translate(typeof(NTAccount));

Alternately, you could just translate the user SID and parse out the domain
name.

Joe K.

Signature

Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--

> Hi Joe,
>
[quoted text clipped - 21 lines]
>> > domain
>> > that this user object belongs to?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.