Re: Retrieving User's Groups from Active Directory using ASP.NET
From: L Magarian (LMagarian_at_discussions.microsoft.com)
Date: 09/28/04
- Previous message: anonymous_at_discussions.microsoft.com: "Re: problem writing a file"
- In reply to: Paul Clement: "Re: Retrieving User's Groups from Active Directory using ASP.NET"
- Next in thread: Joe Kaplan \(MVP - ADSI\): "Re: Retrieving User's Groups from Active Directory using ASP.NET"
- Reply: Joe Kaplan \(MVP - ADSI\): "Re: Retrieving User's Groups from Active Directory using ASP.NET"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 28 Sep 2004 11:59:02 -0700
The error is: "The specified domain either does not exist or could not be
contacted ", and is thrown by the FindOne() method.
The path I'm using looks like LDAP://company.com/CN=My Name,OU=User
Accounts,OU=Accounts,DC=company,DC=com
This is the method I'm using to get the user's groups:
public string GetGroups()
{
DirectorySearcher search = new DirectorySearcher(_path);
search.Filter = "(cn=" + _filterAttribute + ")";
search.PropertiesToLoad.Add("memberOf");
StringBuilder groupNames = new StringBuilder();
SearchResult result = search.FindOne();
int propertyCount = result.Properties["memberOf"].Count;
int equalsIndex, commaIndex;
for( int i = 0; i < propertyCount; i++)
{
String dn = (String)result.Properties["memberOf"][i];
equalsIndex = dn.IndexOf("=", 1);
commaIndex = dn.IndexOf(",", 1);
if (-1 == equalsIndex)
{
return null;
}
groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex)
- 1));
groupNames.Append("|");
}
return groupNames.ToString();
}
"Paul Clement" wrote:
> On Tue, 28 Sep 2004 01:51:03 -0700, "L Magarian" <LMagarian@discussions.microsoft.com> wrote:
>
> ¤ I'm using forms based authentication and LDAP to authenticate a user against
> ¤ Active Directory. This is working fine.
> ¤
> ¤ The point where I'm stuck is retireving the groups this user is assigned.
> ¤
> ¤ My web server and active directory servers are different machines. When I
> ¤ test by deploying the web app on the active directory machine it does work.
> ¤ However, I will not be able to employ this work around in the production
> ¤ setting.
> ¤
> ¤ Can anyone advise me as to how retrieve these user groups?
> ¤
> ¤ Are there special settings for searching the Active Directory when running a
> ¤ web app off a different server?
>
> Could you indicate what type of error you are receiving and identify the line of code where it
> occurs?
>
>
> Paul ~~~ pclement@ameritech.net
> Microsoft MVP (Visual Basic)
>
- Previous message: anonymous_at_discussions.microsoft.com: "Re: problem writing a file"
- In reply to: Paul Clement: "Re: Retrieving User's Groups from Active Directory using ASP.NET"
- Next in thread: Joe Kaplan \(MVP - ADSI\): "Re: Retrieving User's Groups from Active Directory using ASP.NET"
- Reply: Joe Kaplan \(MVP - ADSI\): "Re: Retrieving User's Groups from Active Directory using ASP.NET"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|