I am writing a web page that I want to use pass through user authentication from the network. I am using DirectoryServices to get the current logon username and authenticating it against a database of users who are authorized to access the site. The problem I am having is that I am getting an error when I try to get the path with "Dim strRoodDAE As String = DSearcher.SearchRoot.Path".
I am able to run the function without error if I use the Visual Studio built in "View in Browser" option that uses port 1345 to show the page, but if I go to the normal port 80 page and click the button to process the function i get the following error:
Error:
Exception Details: System.Runtime.InteropServices.COMException: The specified domain either does not exist or could not be contacted.
VB Function:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim DSearcher As New DirectoryServices.DirectorySearcher
Dim strRootDAE As String = DSearcher.SearchRoot.Path
Dim Dentry As New DirectoryServices.DirectoryEntry(strRootDAE)
DSearcher.Filter = "(& (mailnickname=" & txtLanID.Text & ")(objectClass=user))"
DSearcher.SearchScope = DirectoryServices.SearchScope.Subtree
DSearcher.PropertiesToLoad.Add("mail")
DSearcher.PropertiesToLoad.Add("givenname")
DSearcher.PropertiesToLoad.Add("sn")
DSearcher.PropertyNamesOnly = True
Dim colSearchResults As DirectoryServices.SearchResultCollection
colSearchResults = DSearcher.FindAll
Dim strEmail As String = ""
For Each sResult As DirectoryServices.SearchResult In colSearchResults
Me.txtEmail.Text = sResult.GetDirectoryEntry.Properties("mail").Value.ToString
Me.txtFirstName.Text = sResult.GetDirectoryEntry.Properties("givenname").Value.ToString
Me.txtLastName.Text = sResult.GetDirectoryEntry.Properties("sn").Value.ToString
Next
End Sub
Stack Trace:
[COMException (0x8007054b): The specified domain either does not exist or could not be contacted.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +377678
System.DirectoryServices.DirectoryEntry.Bind() +36
System.DirectoryServices.DirectoryEntry.get_AdsObject() +31
System.DirectoryServices.PropertyValueCollection.PopulateList() +26
System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +49
System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +150
System.DirectoryServices.DirectorySearcher.get_SearchRoot() +92
DOU.frmAddUser.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\frmAddUser.aspx.vb:12
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565