From: Chris Auer on
I am try to get information from AD from within MOSS. My app is
strongly typed, marked as SAFECONTROL in the web.config and the dlls
are in the GAC. But I get this error.

Here is my code (very simple)

public void TestSite()
{
DirectoryEntry AD = new
System.DirectoryServices.DirectoryEntry("LDAP://
OU=SharePointUsers,DC=sharepoint,DC=MyDomain,DC=prv");

foreach (System.DirectoryServices.DirectoryEntry dir in
AD.Children)
{

Response.Write(dir.Name);

}
}

Here is the error

Event Type: Warning
Event Source: ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID: 1309
Date: 10/16/2007
Time: 4:36:36 PM
User: N/A
Computer: SRQVSINDY2
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 10/16/2007 4:36:36 PM
Event time (UTC): 10/16/2007 8:36:36 PM
Event ID: 1403d61f0e8b4124b43b432259efd663
Event sequence: 39
Event occurrence: 2
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/215465162/Root-1-128370400524496191
Trust level: WSS_Minimal
Application Virtual Path: /
Application Path: C:\Inetpub\wwwroot\wss\VirtualDirectories\2501\
Machine name: SERVER2

Process information:
Process ID: 5956
Process name: w3wp.exe
Account name: MEME\Chris.Auer

Exception information:
Exception type: COMException
Exception message: An operations error occurred.


Request information:
Request URL: http://server2:2501/FormServerTemplates/spad.aspx
Request path: /FormServerTemplates/spad.aspx
User host address: 10.16.10.159
User: MEME\Chris.Auer
Is authenticated: True
Authentication Type: NTLM
Thread account name: MEME\Chris.Auer

Thread information:
Thread ID: 1
Thread account name: MEME\Chris.Auer
Is impersonating: False
Stack trace: at
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at
System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry
container)
at System.DirectoryServices.DirectoryEntries.GetEnumerator()
at ActiveDirectoryWebPart.MyTest.TestSite()
at ActiveDirectoryWebPart.MyTest.Page_Load(Object sender, EventArgs
e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.AddedControl(Control control, Int32 index)
at System.Web.UI.ControlCollection.Add(Control child)
at SmartPart.SmartPart.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at
System.Web.UI.WebControls.WebParts.WebPart.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Custom event details:

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.