- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsI am trying to retrieve the user DirectoryEntry by SID which is the unique key to the Active Directory entry. Here is my code:
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
if (!(providerUserKey is SecurityIdentifier))
throw new ArgumentException("Invalid
SecurityIdentifier SID = providerUserKey as SecurityIdentifier;
int SIDLen = SID.BinaryLength;
byte[] SIDBuffer = new byte[SIDLen];
SID.GetBinaryForm(SIDBuffe
string filter = string.Format("(sAMAccount
ConvertByteToStringSid(SID
string[] attribs={"sAMAccountName",
using (DirectoryEntry root = this.GetRootDirectoryEntry
{
using (DirectorySearcher search = new DirectorySearcher(root))
{
try
{
search.Filter = filter;
foreach (string prop in attribs)
{
search.PropertiesToLoad.Ad
}
SearchResult resultItem = search.FindOne(); //Read the path
MembershipUser user = LoadUser(resultItem);
return user;
}
catch (Exception ex)
{
this.lastError="Not Found:" + SID.ToString() + ":" + ex.Message;
System.Diagnostics.Debug.W
return null;
}
}
}
}
/// <summary>
/// Converts the byte to string sid.
/// </summary>
/// <param name="sidBytes">The sid bytes.</param>
/// <returns></returns>
private string ConvertByteToStringSid(Byt
{
StringBuilder strSid = new StringBuilder();
strSid.Append("S-");
try
{
// Add SID revision.
strSid.Append(sidBytes[0].
// Next six bytes are SID authority value.
if (sidBytes[6] != 0 || sidBytes[5] != 0)
{
string strAuth = String.Format
("0x{0:2x}{1:2x}{2:2x}{3:2
(Int16)sidBytes[1],
(Int16)sidBytes[2],
(Int16)sidBytes[3],
(Int16)sidBytes[4],
(Int16)sidBytes[5],
(Int16)sidBytes[6]);
strSid.Append("-");
strSid.Append(strAuth);
}
else
{
Int64 iVal = (Int32)(sidBytes[1]) +
(Int32)(sidBytes[2] << 8) +
(Int32)(sidBytes[3] << 16) +
(Int32)(sidBytes[4] << 24);
strSid.Append("-");
strSid.Append(iVal.ToStrin
}
// Get sub authority count...
int iSubCount = Convert.ToInt32(sidBytes[7
int idxAuth = 0;
for (int i = 0; i < iSubCount; i++)
{
idxAuth = 8 + i * 4;
UInt32 iSubAuth = BitConverter.ToUInt32(sidB
strSid.Append("-");
strSid.Append(iSubAuth.ToS
}
}
catch (Exception ex)
{
lastError = "Error building SID str:"+ex.Message;
System.Diagnostics.Debug.W
return "";
}
return strSid.ToString();
}
It tries to do a directory search with a filter of:
"(sAMAccountName=*)(object
but fails on the 'SearchResult resultItem = search.FindOne()' line with an exception of "Unknown error (0x80005000)"
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: ihenryPosted on 2006-07-10 at 11:44:21ID: 17075687
If you look at the list of generic ADSI error codes in MSDN, the 0x80005000 hex decimal value is referred as E_ADS_BAD_PATHNAME. This means, the AD path you used to bind to AD could be invalid. Take a look closer to the path to see whether it is in the correct syntax and you didn't make any typo like putting a space or some other invalid character. Another possible cause would be security issue, which is the most tricky part when dealing with directory services. But if you can ensure that the user credential you used to run the code or to bind AD (if you explicitly pass user name and password to the DirectoryEntry object) has enough permissions to access and search user information, then all should be good.
library/en -us/dsport al/dsporta l/ director y_services _portal.as p
Look at MSDN library, there should be enough information for you to solve this problem. If you get stumped again, please check back for more discussion.
http://msdn.microsoft.com/