I
iusfani
Hi,
I am trying to connect with Active Directory & Active Directory
Application Mode(AD/AM), and want to pull down user's information, but
unfortunately I am encountering an error, which is like:
<error: an exception of type:
{{System.Runtime.InteropServices.COMException} occured>
Actually what I am trying to do is, I have designed a very simple
ASP.NET page, I am passing userID from there and want to get the user's
profile from AD and/or AD/AM. The code for getting user's information
is:
========================Code Snippet============================
private void getUserData(string UserID)
{
DirectoryEntry de = new DirectoryEntry();
DirectorySearcher aSearcher = new DirectorySearcher(de);
StringBuilder filter = new StringBuilder();
filter.AppendFormat("(anr = {0})", UserID);
aSearcher.Filter = filter.ToString();
SearchResult searchResult = aSearcher.FindOne();
if(searchResult != null){
DirectoryEntry directoryObject = searchResult.GetDirectoryEntry();
if(directoryObject.Properties["name"].Value != null)
name = (string)directoryObject.Properties["name"].Value;
if(directoryObject.Properties["regionID"].Value != null)
this.regionID =
Int32.Parse(directoryObject.Properties["regionID"].Value.ToString());
else
this.regionID = 20;
if (directoryObject.Properties["districtID"].Value!=null)
this.districtID =
Int32.Parse(directoryObject.Properties["districtID"].Value.ToString());
else
this.districtID=20;
if (directoryObject.Properties["homePhone"].Value !=null)
this.claimsOfficerID =
Int32.Parse(directoryObject.Properties["claimsOfficerID"].Value.ToString());
else
this.claimsOfficerID=-1;
}
else
{
throw new NullReferenceException("No such directory entry exists");
}
==========================End Code===============================
Now, When I call getUserData(...) method it throws an error "<error:
{System.Runtime.InteropServices.COMException} occured>"
Could any one please let me know why is that so?
Would be highly appreciated.
Thanks,
Inam
I am trying to connect with Active Directory & Active Directory
Application Mode(AD/AM), and want to pull down user's information, but
unfortunately I am encountering an error, which is like:
<error: an exception of type:
{{System.Runtime.InteropServices.COMException} occured>
Actually what I am trying to do is, I have designed a very simple
ASP.NET page, I am passing userID from there and want to get the user's
profile from AD and/or AD/AM. The code for getting user's information
is:
========================Code Snippet============================
private void getUserData(string UserID)
{
DirectoryEntry de = new DirectoryEntry();
DirectorySearcher aSearcher = new DirectorySearcher(de);
StringBuilder filter = new StringBuilder();
filter.AppendFormat("(anr = {0})", UserID);
aSearcher.Filter = filter.ToString();
SearchResult searchResult = aSearcher.FindOne();
if(searchResult != null){
DirectoryEntry directoryObject = searchResult.GetDirectoryEntry();
if(directoryObject.Properties["name"].Value != null)
name = (string)directoryObject.Properties["name"].Value;
if(directoryObject.Properties["regionID"].Value != null)
this.regionID =
Int32.Parse(directoryObject.Properties["regionID"].Value.ToString());
else
this.regionID = 20;
if (directoryObject.Properties["districtID"].Value!=null)
this.districtID =
Int32.Parse(directoryObject.Properties["districtID"].Value.ToString());
else
this.districtID=20;
if (directoryObject.Properties["homePhone"].Value !=null)
this.claimsOfficerID =
Int32.Parse(directoryObject.Properties["claimsOfficerID"].Value.ToString());
else
this.claimsOfficerID=-1;
}
else
{
throw new NullReferenceException("No such directory entry exists");
}
==========================End Code===============================
Now, When I call getUserData(...) method it throws an error "<error:
{System.Runtime.InteropServices.COMException} occured>"
Could any one please let me know why is that so?
Would be highly appreciated.
Thanks,
Inam