I am using the following code to query ActiveDirectory :
string pStrUser = this.Context.User.Identity.Name;
using (DirectorySearcher objDS = new
DirectorySearcher("objectCategory=User"))
{
objDS.Filter = "(SAMAccountName=" + pStrUser + ")";
using (DirectoryEntry objUser = new
DirectoryEntry(objDS.FindOne().Path))
{
System.DirectoryServices.PropertyCollection
colProperties = objUser.Properties;
PropertyValueCollection colPropertyValues =
colProperties["memberOf"];
foreach (string strGroup in colPropertyValues)
{
pStrUser += strGroup.ToLower();
}
}
}
This works fine locally but if I attempt to access my page from a
non-local machine i get the following error :
"The specified domain either does not exist or could not be contacted."
I'm assuming this is an IIS configuration issue?
TIA
Iain
I'd see 2 main root causes:
1) The server cannot resolve the name of the domain (try with nslookup
locally on the server to resolve the domain name)
2) Communication between the server and domain controllers is prevented
(lack of IP route, firewall...). Try with tracert mydc.mydomain.local on the
server or using ldp.exe and a simple "connect", both locally on the server.
--
Marc Lognoul [MCSE, MCTS, MVP]
Heureux celui qui a pu p�n�trer les causes secr�tes des choses
Happy is the one who could enter the secret causes of things
Blog EN: http://www.marc-antho-etc.net/blog/
Blog FR: http://www.marc-antho-etc.net/blogfr/
"Iain" <ia...@test.co.uk> wrote in message
news:esQOIujT...@TK2MSFTNGP05.phx.gbl...
It is easy to fix by providing a DirectoryEntry to the DirectorySearcher
constructor that contains the name of the domain to access:
LDAP://yourdomain.com/DC=yourdomain,DC=com
This should work fine.
Note also that if you are using Windows authentication in your app, you are
wasting time doing an LDAP lookup to get the user's group membership. Just
cast the User.Identity to a WindowsIdentity object and access the Groups
property. You can translate those to friendly names with the Translate
method if you need to. Much easier!
Also, memberOf does not contain nested groups or primary group, so using it
is an incomplete solution to group membership expansion.
--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
"Iain" <ia...@test.co.uk> wrote in message
news:esQOIujT...@TK2MSFTNGP05.phx.gbl...
Just to clarify what requires changing :
string pStrUser = this.Context.User.Identity.Name;
using (DirectorySearcher objDS = new
DirectorySearcher("objectCategory=User"))
{
objDS.Filter = "(SAMAccountName=" + pStrUser + ")";
using (DirectoryEntry objUser = new
DirectoryEntry(objDS.FindOne().Path)) <-----------Into here i need to
pass in the domain name ---------------->
using System.DirectoryServices.ActiveDirectory;
...
Domain d = Domain.GetDomain("yourdomain.com");
DirectoryEntry root = d.GetDirectoryEntry();
using (DirectorySearcher objDS = new DirectorySearcher())
{
objDS.SearchRoot = root;
....
}
Also, like I said you may be wasting your time reading group membership via
LDAP to begin with.
--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
"Iain" <ia...@test.co.uk> wrote in message
news:OREl5vMU...@TK2MSFTNGP05.phx.gbl...