Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > How to get ou of an user

Reply
Thread Tools

How to get ou of an user

 
 
Guest
Posts: n/a
 
      05-25-2005
Hi
I wonder if there is other / faster ways to get ou of the login user?

Here is what I can think of
- authentication
- Search with SAMAccountName=<username entered>
- set PropertiesToLoad.Add("distinguishedName")
- parse the OU= string from the property returned

TIA

--



 
Reply With Quote
 
 
 
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      05-25-2005
That will probably work fine. You might also consider p/invoking the
TranslateName Windows API as it can convert from login name to distinguished
name.

If you do parse, be careful about encoded "," characters in the DN. You
can't be 100% sure that a simple Split on the comma will work as the name
component can have a "," in it if it is preceded by "\". Thus you could
have:

CN=Doe\, Jane,OU=people,DC=domain,DC=com

If your AD doesn't use that naming convention, you are fine, but just
remember that it is legal syntax and could cause funny bugs at runtime in
code that seems to work fine 95% of the time.

Joe K.

<dl> wrote in message news:%(E-Mail Removed)...
> Hi
> I wonder if there is other / faster ways to get ou of the login user?
>
> Here is what I can think of
> - authentication
> - Search with SAMAccountName=<username entered>
> - set PropertiesToLoad.Add("distinguishedName")
> - parse the OU= string from the property returned
>
> TIA
>
> --
>
>
>



 
Reply With Quote
 
 
 
 
Jan Peter Stotz
Guest
Posts: n/a
 
      05-25-2005
dl schrieb:

> Here is what I can think of
> - authentication
> - Search with SAMAccountName=<username entered>
> - set PropertiesToLoad.Add("distinguishedName")
> - parse the OU= string from the property returned


Why parsing the dn when you can just ask the corresponding class?

If you search the account by using the DirectorySearcher class, as result
you will get an object of type SearchResult. Call on this object
..GetDirectoryEntry().Parent.Path and you get what you want.

Jan
 
Reply With Quote
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      05-25-2005
Yep, that works too. Thanks for pointing that out.

Joe K.

"Jan Peter Stotz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> dl schrieb:
>
>> Here is what I can think of
>> - authentication
>> - Search with SAMAccountName=<username entered>
>> - set PropertiesToLoad.Add("distinguishedName")
>> - parse the OU= string from the property returned

>
> Why parsing the dn when you can just ask the corresponding class?
>
> If you search the account by using the DirectorySearcher class, as result
> you will get an object of type SearchResult. Call on this object
> .GetDirectoryEntry().Parent.Path and you get what you want.
>
> Jan



 
Reply With Quote
 
Guest
Posts: n/a
 
      05-26-2005
Thanks Joe.

"Joe Kaplan (MVP - ADSI)" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> That will probably work fine. You might also consider p/invoking the
> TranslateName Windows API as it can convert from login name to

distinguished
> name.
>
> If you do parse, be careful about encoded "," characters in the DN. You
> can't be 100% sure that a simple Split on the comma will work as the name
> component can have a "," in it if it is preceded by "\". Thus you could
> have:
>
> CN=Doe\, Jane,OU=people,DC=domain,DC=com
>
> If your AD doesn't use that naming convention, you are fine, but just
> remember that it is legal syntax and could cause funny bugs at runtime in
> code that seems to work fine 95% of the time.
>
> Joe K.
>
> <dl> wrote in message news:%(E-Mail Removed)...
> > Hi
> > I wonder if there is other / faster ways to get ou of the login user?
> >
> > Here is what I can think of
> > - authentication
> > - Search with SAMAccountName=<username entered>
> > - set PropertiesToLoad.Add("distinguishedName")
> > - parse the OU= string from the property returned
> >
> > TIA
> >
> > --
> >
> >
> >

>
>



 
Reply With Quote
 
Guest
Posts: n/a
 
      05-27-2005
Thanks Jan. But what is returned by the GetDirectoryEntry().Parent.Path?
can you give a sample format please?
TIA

"Jan Peter Stotz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> dl schrieb:
>
> > Here is what I can think of
> > - authentication
> > - Search with SAMAccountName=<username entered>
> > - set PropertiesToLoad.Add("distinguishedName")
> > - parse the OU= string from the property returned

>
> Why parsing the dn when you can just ask the corresponding class?
>
> If you search the account by using the DirectorySearcher class, as result
> you will get an object of type SearchResult. Call on this object
> .GetDirectoryEntry().Parent.Path and you get what you want.
>
> Jan



 
Reply With Quote
 
Jan Peter Stotz
Guest
Posts: n/a
 
      05-27-2005
dl wrote:

> Thanks Jan. But what is returned by the GetDirectoryEntry().Parent.Path?
> can you give a sample format please?


The "DirectoryEntry.Path Property" is a String property. For a detailed
description search the .Net Framwork SDK Documentation.

VB.NET:

Dim searcher as new DirectorySearcher("LDAP://dc=yourdomain,dc=com")
searcher.Filter="(&(objectClass=user)(samaccountna me=" & username & "))"
Dim result as SearchResult = searcher.FindOne
Dim userEntry as DirectoryEntry = result.GetDirectoryEntry()
Dim containerEntry as DirectoryEntry = userEntry.Parent
Dim String containerPath = containerEntry.Path

Jan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Hi I have one web application and i want to get the number of users who are currently accessing the application. Also I want to get the user details of each user, which is stored in a database. How can I do this? Pls help. Getting No: and anu Java 11 05-12-2005 03:25 PM
Re: How to get user's full name using HttpContext.Current.User Steve C. Orr [MVP, MCSD] ASP .Net 0 07-23-2004 10:14 PM
Re: How to get user's full name using HttpContext.Current.User Mike Newton ASP .Net 0 07-23-2004 03:56 PM



Advertisments