473,769 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Active Directory FindOne Problems

I'm trying to use the DirectorySearch er.FindOne() method to get the display
name of the current user. The code runs on a server behind a web service.
Everything works fine when I run it on my local machine but the FindOne()
method fails when I deploy it to the server. I'm at a loss and any help
would be appreciated.

This is the code that works on my local machine but not on the server.

DirectorySearch er search = new DirectorySearch er("LDAP://RootDSE");
search.Filter = String.Format(" (SAMAccountName =" + m_UserName + ")");
search.Properti esToLoad.Add("d isplayName");

SearchResult result = search.FindOne( ); // This fails on the server
m_DisplayName = result.Properti es["displaynam e"][0] == null ? "" :
result.Properti es["displaynam e"][0].ToString();

May 22 '07 #1
7 14242
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:08******** *************** ***********@mic rosoft.com...
I'm trying to use the DirectorySearch er.FindOne() method to get the
display
name of the current user. The code runs on a server behind a web service.
Everything works fine when I run it on my local machine but the FindOne()
method fails when I deploy it to the server. I'm at a loss and any help
would be appreciated.

This is the code that works on my local machine but not on the server.

DirectorySearch er search = new DirectorySearch er("LDAP://RootDSE");
search.Filter = String.Format(" (SAMAccountName =" + m_UserName + ")");
search.Properti esToLoad.Add("d isplayName");

SearchResult result = search.FindOne( ); // This fails on the server
m_DisplayName = result.Properti es["displaynam e"][0] == null ? "" :
result.Properti es["displaynam e"][0].ToString();

LDAP://RootDSE means that you are binding to the root of the current user's
login domain. That means that this can only be used when your application
runs in a domain account on the server.

Willy.

May 22 '07 #2


"Willy Denoyette [MVP]" wrote:
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:08******** *************** ***********@mic rosoft.com...
I'm trying to use the DirectorySearch er.FindOne() method to get the
display
name of the current user. The code runs on a server behind a web service.
Everything works fine when I run it on my local machine but the FindOne()
method fails when I deploy it to the server. I'm at a loss and any help
would be appreciated.

This is the code that works on my local machine but not on the server.

DirectorySearch er search = new DirectorySearch er("LDAP://RootDSE");
search.Filter = String.Format(" (SAMAccountName =" + m_UserName + ")");
search.Properti esToLoad.Add("d isplayName");

SearchResult result = search.FindOne( ); // This fails on the server
m_DisplayName = result.Properti es["displaynam e"][0] == null ? "" :
result.Properti es["displaynam e"][0].ToString();


LDAP://RootDSE means that you are binding to the root of the current user's
login domain. That means that this can only be used when your application
runs in a domain account on the server.

Willy.

I get the same results even if I use "LDAP://DC=company_name ,DC=local".
Everything is running in Windows Authentication so we do have the users token.
May 22 '07 #3
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:32******** *************** ***********@mic rosoft.com...
>

"Willy Denoyette [MVP]" wrote:
>"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:08******* *************** ************@mi crosoft.com...
I'm trying to use the DirectorySearch er.FindOne() method to get the
display
name of the current user. The code runs on a server behind a web
service.
Everything works fine when I run it on my local machine but the
FindOne()
method fails when I deploy it to the server. I'm at a loss and any
help
would be appreciated.

This is the code that works on my local machine but not on the server.

DirectorySearch er search = new DirectorySearch er("LDAP://RootDSE");
search.Filter = String.Format(" (SAMAccountName =" + m_UserName + ")");
search.Properti esToLoad.Add("d isplayName");

SearchResult result = search.FindOne( ); // This fails on the server
m_DisplayName = result.Properti es["displaynam e"][0] == null ? "" :
result.Properti es["displaynam e"][0].ToString();


LDAP://RootDSE means that you are binding to the root of the current
user's
login domain. That means that this can only be used when your application
runs in a domain account on the server.

Willy.


I get the same results even if I use "LDAP://DC=company_name ,DC=local".
Everything is running in Windows Authentication so we do have the users
token.

No, specifying this will try to bind to the "login domain" of the current
user, when the current user is not logged-in to a domain, you have to
specify the "domain name" you want to bind to.
LDAP://domain/dc=...;
or the name of the "domain controller":

LDAP://dc/dc=...;

Willy.
May 23 '07 #4


"Willy Denoyette [MVP]" wrote:
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:32******** *************** ***********@mic rosoft.com...


"Willy Denoyette [MVP]" wrote:
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:08******** *************** ***********@mic rosoft.com...
I'm trying to use the DirectorySearch er.FindOne() method to get the
display
name of the current user. The code runs on a server behind a web
service.
Everything works fine when I run it on my local machine but the
FindOne()
method fails when I deploy it to the server. I'm at a loss and any
help
would be appreciated.

This is the code that works on my local machine but not on the server.

DirectorySearch er search = new DirectorySearch er("LDAP://RootDSE");
search.Filter = String.Format(" (SAMAccountName =" + m_UserName + ")");
search.Properti esToLoad.Add("d isplayName");

SearchResult result = search.FindOne( ); // This fails on the server
m_DisplayName = result.Properti es["displaynam e"][0] == null ? "" :
result.Properti es["displaynam e"][0].ToString();

LDAP://RootDSE means that you are binding to the root of the current
user's
login domain. That means that this can only be used when your application
runs in a domain account on the server.

Willy.

I get the same results even if I use "LDAP://DC=company_name ,DC=local".
Everything is running in Windows Authentication so we do have the users
token.


No, specifying this will try to bind to the "login domain" of the current
user, when the current user is not logged-in to a domain, you have to
specify the "domain name" you want to bind to.
LDAP://domain/dc=...;
or the name of the "domain controller":

LDAP://dc/dc=...;

Willy.

Everything is running in the same domain, we don't allow any outside access.
I've tried using LDAP with the domain and without but I still get the same
problem.

Is this the only way to get the display name of the user or is the another
approach I can take?
May 23 '07 #5
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:72******** *************** ***********@mic rosoft.com...
>

"Willy Denoyette [MVP]" wrote:
>"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:32******* *************** ************@mi crosoft.com...
>

"Willy Denoyette [MVP]" wrote:

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:08******* *************** ************@mi crosoft.com...
I'm trying to use the DirectorySearch er.FindOne() method to get the
display
name of the current user. The code runs on a server behind a web
service.
Everything works fine when I run it on my local machine but the
FindOne()
method fails when I deploy it to the server. I'm at a loss and any
help
would be appreciated.

This is the code that works on my local machine but not on the
server.

DirectorySearch er search = new DirectorySearch er("LDAP://RootDSE");
search.Filter = String.Format(" (SAMAccountName =" + m_UserName +
")");
search.Properti esToLoad.Add("d isplayName");

SearchResult result = search.FindOne( ); // This fails on the server
m_DisplayName = result.Properti es["displaynam e"][0] == null ? "" :
result.Properti es["displaynam e"][0].ToString();

LDAP://RootDSE means that you are binding to the root of the current
user's
login domain. That means that this can only be used when your
application
runs in a domain account on the server.

Willy.

I get the same results even if I use "LDAP://DC=company_name ,DC=local".
Everything is running in Windows Authentication so we do have the users
token.


No, specifying this will try to bind to the "login domain" of the current
user, when the current user is not logged-in to a domain, you have to
specify the "domain name" you want to bind to.
LDAP://domain/dc=...;
or the name of the "domain controller":

LDAP://dc/dc=...;

Willy.


Everything is running in the same domain, we don't allow any outside
access.
I've tried using LDAP with the domain and without but I still get the same
problem.

Is this the only way to get the display name of the user or is the another
approach I can take?

What problem, Any exception message perhaps?

You need to bind using the "Domain name" or "DC sever" name, and you need to
specify explicit credentials and the authentication type. Also, you need to
be sure that the "domain name" and/or the "dc server name" can be resolved
through a DNS lookup, if you are not sure it's the case, you can try using
the IP address of the DC.

("LDAP://domainName/cn=...,dc=...,d c=...", "domainuser ", "hispwd",
AuthenticationT ypes.ServerBind );

or...

("LDAP://DCName/cn=...,dc=...,d c=...", "domainuser ", "hispwd",
AuthenticationT ypes.ServerBind );
Note that it doesn't matter whether you run in a single domain or not, this
is something YOU know, but not the ADSI client code.

Willy.

May 23 '07 #6


"Willy Denoyette [MVP]" wrote:
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:72******** *************** ***********@mic rosoft.com...


"Willy Denoyette [MVP]" wrote:
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:32******** *************** ***********@mic rosoft.com...
"Willy Denoyette [MVP]" wrote:

"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:08******** *************** ***********@mic rosoft.com...
I'm trying to use the DirectorySearch er.FindOne() method to get the
display
name of the current user. The code runs on a server behind a web
service.
Everything works fine when I run it on my local machine but the
FindOne()
method fails when I deploy it to the server. I'm at a loss and any
help
would be appreciated.

This is the code that works on my local machine but not on the
server.

DirectorySearch er search = new DirectorySearch er("LDAP://RootDSE");
search.Filter = String.Format(" (SAMAccountName =" + m_UserName +
")");
search.Properti esToLoad.Add("d isplayName");

SearchResult result = search.FindOne( ); // This fails on the server
m_DisplayName = result.Properti es["displaynam e"][0] == null ? "" :
result.Properti es["displaynam e"][0].ToString();

LDAP://RootDSE means that you are binding to the root of the current
user's
login domain. That means that this can only be used when your
application
runs in a domain account on the server.

Willy.

I get the same results even if I use "LDAP://DC=company_name ,DC=local".
Everything is running in Windows Authentication so we do have the users
token.
No, specifying this will try to bind to the "login domain" of the current
user, when the current user is not logged-in to a domain, you have to
specify the "domain name" you want to bind to.
LDAP://domain/dc=...;
or the name of the "domain controller":

LDAP://dc/dc=...;

Willy.

Everything is running in the same domain, we don't allow any outside
access.
I've tried using LDAP with the domain and without but I still get the same
problem.

Is this the only way to get the display name of the user or is the another
approach I can take?


What problem, Any exception message perhaps?

You need to bind using the "Domain name" or "DC sever" name, and you need to
specify explicit credentials and the authentication type. Also, you need to
be sure that the "domain name" and/or the "dc server name" can be resolved
through a DNS lookup, if you are not sure it's the case, you can try using
the IP address of the DC.

("LDAP://domainName/cn=...,dc=...,d c=...", "domainuser ", "hispwd",
AuthenticationT ypes.ServerBind );

or...

("LDAP://DCName/cn=...,dc=...,d c=...", "domainuser ", "hispwd",
AuthenticationT ypes.ServerBind );
Note that it doesn't matter whether you run in a single domain or not, this
is something YOU know, but not the ADSI client code.

Willy.
If I understand you correctly, I need to use a different account to
communicate with the DC instead of the current user. If not, I'm not sure
how to resolve this because I don't know the password for the user.

This is the error I get.

************** Exception Text **************
System.Web.Serv ices.Protocols. SoapException: Server was unable to process
request. ---An operations error occurred.

at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters)
at WS.GetList() in C:\Project\Web References\WS\R eference.cs:lin e 760
at frm.LoadForm() in C:\Project\frm. cs:line 30
at frm.frm_Load(Ob ject sender, EventArgs e) in C:\Project\frm. cs:line 499
at System.EventHan dler.Invoke(Obj ect sender, EventArgs e)
at System.Windows. Forms.Form.OnLo ad(EventArgs e)
at System.Windows. Forms.Form.OnCr eateControl()
at System.Windows. Forms.Control.C reateControl(Bo olean fIgnoreVisible)
at System.Windows. Forms.Control.C reateControl()
at System.Windows. Forms.Control.W mShowWindow(Mes sage& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.Form.WmSh owWindow(Messag e& m)
at System.Windows. Forms.Form.WndP roc(Message& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
May 23 '07 #7


"Mike" wrote:
>

"Willy Denoyette [MVP]" wrote:
"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
news:72******** *************** ***********@mic rosoft.com...
>
>
"Willy Denoyette [MVP]" wrote:
>
>"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
>news:32******* *************** ************@mi crosoft.com...
>
>
"Willy Denoyette [MVP]" wrote:
>
>"Mike" <Mi**@discussio ns.microsoft.co mwrote in message
>news:08******* *************** ************@mi crosoft.com...
I'm trying to use the DirectorySearch er.FindOne() method to get the
display
name of the current user. The code runs on a server behind a web
service.
Everything works fine when I run it on my local machine but the
FindOne()
method fails when I deploy it to the server. I'm at a loss and any
help
would be appreciated.
>
This is the code that works on my local machine but not on the
server.
>
DirectorySearch er search = new DirectorySearch er("LDAP://RootDSE");
search.Filter = String.Format(" (SAMAccountName =" + m_UserName +
")");
search.Properti esToLoad.Add("d isplayName");
>
SearchResult result = search.FindOne( ); // This fails on the server
m_DisplayName = result.Properti es["displaynam e"][0] == null ? "" :
result.Properti es["displaynam e"][0].ToString();
>
>>
>>
>LDAP://RootDSE means that you are binding to the root of the current
>user's
>login domain. That means that this can only be used when your
>application
>runs in a domain account on the server.
>>
>Willy.
>>
>>
>
I get the same results even if I use "LDAP://DC=company_name ,DC=local".
Everything is running in Windows Authentication so we do have the users
token.
>>
>>
>No, specifying this will try to bind to the "login domain" of the current
>user, when the current user is not logged-in to a domain, you have to
>specify the "domain name" you want to bind to.
>LDAP://domain/dc=...;
>or the name of the "domain controller":
>>
>LDAP://dc/dc=...;
>>
>Willy.
>>
>>
>
Everything is running in the same domain, we don't allow any outside
access.
I've tried using LDAP with the domain and without but I still get the same
problem.
>
Is this the only way to get the display name of the user or is the another
approach I can take?

What problem, Any exception message perhaps?

You need to bind using the "Domain name" or "DC sever" name, and you need to
specify explicit credentials and the authentication type. Also, you need to
be sure that the "domain name" and/or the "dc server name" can be resolved
through a DNS lookup, if you are not sure it's the case, you can try using
the IP address of the DC.

("LDAP://domainName/cn=...,dc=...,d c=...", "domainuser ", "hispwd",
AuthenticationT ypes.ServerBind );

or...

("LDAP://DCName/cn=...,dc=...,d c=...", "domainuser ", "hispwd",
AuthenticationT ypes.ServerBind );
Note that it doesn't matter whether you run in a single domain or not, this
is something YOU know, but not the ADSI client code.

Willy.

If I understand you correctly, I need to use a different account to
communicate with the DC instead of the current user. If not, I'm not sure
how to resolve this because I don't know the password for the user.

This is the error I get.

************** Exception Text **************
System.Web.Serv ices.Protocols. SoapException: Server was unable to process
request. ---An operations error occurred.

at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters)
at WS.GetList() in C:\Project\Web References\WS\R eference.cs:lin e 760
at frm.LoadForm() in C:\Project\frm. cs:line 30
at frm.frm_Load(Ob ject sender, EventArgs e) in C:\Project\frm. cs:line 499
at System.EventHan dler.Invoke(Obj ect sender, EventArgs e)
at System.Windows. Forms.Form.OnLo ad(EventArgs e)
at System.Windows. Forms.Form.OnCr eateControl()
at System.Windows. Forms.Control.C reateControl(Bo olean fIgnoreVisible)
at System.Windows. Forms.Control.C reateControl()
at System.Windows. Forms.Control.W mShowWindow(Mes sage& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.Form.WmSh owWindow(Messag e& m)
at System.Windows. Forms.Form.WndP roc(Message& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

I found the problem.

The server where the web service resides needs to have the delegation set in
AD to trust the computer for delegation to any service.

May 24 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3948
by: Toufani | last post by:
Hi everybody, I want to retrieve information about objects in active directory windows 2000 and their properties. I got some codes that don't work absolutely. for example I can't retrieve users list and group list separatedly.there is my code that downloaded from the internet : public class LdapAuthentication { private string _path;
1
3310
by: Amadelle | last post by:
Hi all, I am so desparately in need of some guidance! After two days of struggling I still can't connect to the Active Directory server. I have used so many different ways and so many different string paths and I still don't have a successful connection. Things I have tried: Using Directory Searcher: DirectorySearcher ds = new DirectorySearcher(); ds.SearchRoot = new DirectoryEntry();
10
5453
by: huzz | last post by:
I have web application that quaries the Active Directory to get user details.. everything works fine but someday I'll get System.Runtime.InteropServices.COMExection and if I restart the client machine then it works again. here is one of the method where am calling the AD public bool UserExist(string UserName) {
0
1848
by: Kenneth Keeley | last post by:
Hi, I have been working on a Login page that uses ADSI to authenicate the users. I had this all working on my test system and on a second system connected to the live domain. Now it will only work on my test system which is a win2K Server running as a domain controller and web server. The second system is a win2K workstation connected to the live win2K domain controller, This computer was able to run the code in the past and now all I keep...
1
3895
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://domain") Dim mySearcher As New DirectorySearcher(enTry) Dim resEnt As SearchResult mySearcher.Filter = ("(objectClass=*)") mySearcher.SearchScope = SearchScope.Subtree
10
4065
by: Hriday | last post by:
Hi there, Please help me..It is urgent This is Hriday, working on windows authentication with Active Directory... My requirment is when a user sends a request to my web Applicatoin I want to Pop up windows Authentication box so that user will give his userId, Password & domain name for authenticaion. After that I want to take these three info of user and make a search in Active Directory.
3
3007
by: Phil Kelly | last post by:
Hi! I hope someone can help me here because I'm tearing my hair out (what little there is of it!) trying to figure out what's going on with the code below. I'm passing an Active Directory CN of a user object (like CN=Phil,OU=Users,DC=Test,DC=local) to the doRep() function, then have the function search for the user in AD ('FindOne') Then, I'm trying to get the code to msgbox the directory entry name.... but
3
2053
by: Susan | last post by:
Hello all, My ASP.NET application seems to have intermittent problems when connecting to Active Directory server. Most of the time the Active Directory app works fine then suddenly fails and will repeatedly occur for a period of time then start working fine again. ASP.NET application uses windows authentication. I am attaching the code for reference: -----------------------------
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.