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 / ASP.NET / Web Services / December 2005

Tip: Looking for answers? Try searching our database.

LDAP to Domain Controller

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mario - 28 Jul 2004 09:19 GMT
Hi,

i am new on VB .net and i want to list all Active Directory Users in a WebInterface.
It is no problem in Windows Applications to list users, but in Web Application i allay get the following error

Server Error in '/IP-Phone-Admin' Application.
--------------------------------------------------------------------------------

The specified domain either does not exist or could not be contacted
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The specified domain either does not exist or could not be contacted

Source Error:

Line 33:     Dim result As System.DirectoryServices.SearchResult
Line 34:     mySearcher.Filter = "(ObjectClass=user)"
Line 35:     For Each result In mySearcher.FindAll()
Line 36:       DropDown.Items.Add(result.GetDirectoryEntry().Path)
Line 37:     Next


Source File: C:\Inetpub\wwwroot\IP-Phone-Admin\WebForm1.aspx.vb    Line: 35

Stack Trace:

[COMException (0x8007054b): The specified domain either does not exist or could not be contacted]
  System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
  System.DirectoryServices.DirectoryEntry.Bind()
  System.DirectoryServices.DirectoryEntry.get_AdsObject()
  System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
  System.DirectoryServices.DirectorySearcher.FindAll()
  IP_Phone_Admin.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\IP-Phone-Admin\WebForm1.aspx.vb:35
  System.Web.UI.Control.OnLoad(EventArgs e)
  System.Web.UI.Control.LoadRecursive()
  System.Web.UI.Page.ProcessRequestMain()



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

I hope that anybody can help me
thanx

mario
Emil Kvarnhammar - 28 Jul 2004 09:56 GMT
Hi,

Please show the code where you create your DirectorySearcher.

Looks like your web server can't find the domain controller of the domain
you specify
for the entry that you use to create your searcher with.

regards
Emil Kvarnhammar

> Hi,
>
[quoted text clipped - 6 lines]
> The specified domain either does not exist or could not be contacted
> Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information
about the error and where it originated in the code.

> Exception Details: System.Runtime.InteropServices.COMException: The specified domain either does not exist or could not be contacted
>
[quoted text clipped - 28 lines]
>
> mario
Mario - 28 Jul 2004 10:15 GMT
Hi,
thanx for your help

------------------------------------------------------------------
Dim entry As New DirectoryServices.DirectoryEntry("LDAP://ou=myusers,dc=nts,dc=at")
   Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)
   Dim result As System.DirectoryServices.SearchResult
   mySearcher.Filter = "(ObjectClass=user)"
   For Each result In mySearcher.FindAll()
     DropDown.Items.Add(result.GetDirectoryEntry().Path)
   Next
--------------------------------------------------------------

this code works fine in a windows application

> Hi,
>
[quoted text clipped - 62 lines]
> >
> > mario
postbryan - 28 Dec 2005 17:43 GMT
I have the same problem.  

It is to do with Security in login credentials via IIS, which is not a
problem with Windows apps, as they use Windows Authentication.

I discovered this link to possible solutions:

http://support.microsoft.com/default.aspx?scid=kb;en-us;329986
postbryan - 28 Dec 2005 23:07 GMT
I finally got this to work in asp.net.  
There are actually 2 ways to do it.

The first method is the simplest, using the full path to the domain.   This
method will not work if you try to point to a specific AD container, using
paths like CN=x, DC=y, Dc=z OU=a etc.

       sADPath = "LDAP://sdp-dc3.sdptech.com"
       sADUser = "adminguy"
       sADPassword = "adminpwd"
       oDirectoryEntry = New DirectoryEntry
       oDirectoryEntry.Path = sADPath
       oDirectoryEntry.Password = sADPassword
       oDirectoryEntry.Username = sADUser
       oDirectoryEntry.AuthenticationType = AuthenticationTypes.Secure

so, how do you get to a specific container to query it?  
You need to use the DirectorySearcher object and filter - I wont go into that
here, there are many examples of using the DirectorySearcher on the web

Anyway, you filter it such as:

(&(objectClass=user) (objectCategory=Person) (!(telephoneNumber=*)))

OK, the second method is a bit tricker, but allows you to use container
pointers in the LDAP declaration.

       Dim oDirectoryEntry As DirectoryEntry
       Dim sADPath As String

       sADPath = "LDAP://DC=sdptech,DC=com,CN=Users"
       oDirectoryEntry = New DirectoryEntry
       oDirectoryEntry.Path = sADPath

if you try running this, you get errors.  You need to set up IIS and also the
web config file as follows:

In IIS, navigate to the Virtual directory for the web application
In the console, select the aspx page that runs the code that accesses the
Active Directory.
Click "Properties" from popup menu, then select the "File Security" tab.
Click the "Edit" button to display the "Authentication Methods" form.

Ensure that "Integrated Windows Authentication" is checked.
Ensure that "Anonymous User" is checked.
All other options should be unchecked.

In the "Anonymous User" section:
select a DOMAIN user name (such as domain administrator) and user password
ensure that "Allow IIS to control password" is unchecked.

Finally, in your application web config file, ensure you have the following
entry:

   <authentication mode="Windows" />
   <identity impersonate="true"  />

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.