奇怪的事情发生......
我被迫迁移到新的开发人员计算机(Windows Server 2008 R2到2012)。 完全相同的代码在新机器上不起作用。
public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
MembershipUserCollection retvalue = new MembershipUserCollection();
string ldapConnectionString = _configuration.GetConnectionString();
using (DirectoryEntry de
= new DirectoryEntry(ldapConnectionString, _configuration.SearchAccount, _configuration.SearchAccountPassword, AuthenticationTypes.ServerBind))
{
string filter = string.Format("(&(objectClass=Person)(CUSTOMemail={0}))", emailToMatch);
DirectorySearcher ds = new DirectorySearcher(de, filter, new[] { "cn", "CUSTOMemail" }, SearchScope.Subtree);
SearchResultCollection collection = ds.FindAll();
totalRecords = collection.Count;
int pagesCount = (totalRecords > pageSize) ? (int)Math.Ceiling((double)(totalRecords / pageSize)) : 1;
if (pageIndex > pagesCount - 1)
throw new IndexOutOfRangeException("PageIndex exceeds max PageIndex");
for (int i = pageIndex * pageSize; i < totalRecords; i++)
{
DirectoryEntry userDirectoryEntry = collection[i].GetDirectoryEntry();
string userName = userDirectoryEntry.Properties["cn"].Value as string;
string providerUserKey = userDirectoryEntry.Path;
string email = userDirectoryEntry.Properties["CUSTOMemail"].Value as string;
MembershipUser mu = new MembershipUser(
providerName: Name,
name: userName,
providerUserKey: providerUserKey,
email: email,
passwordQuestion: null,
comment: null,
isApproved: true,
isLockedOut: false,
creationDate: DateTime.MinValue,
lastLoginDate: DateTime.MinValue,
lastActivityDate: DateTime.MinValue,
lastPasswordChangedDate: DateTime.MinValue,
lastLockoutDate: DateTime.MinValue);
retvalue.Add(mu);
}
}
return retvalue;
}
代码在尝试读取CUSTOMemail属性时失败。系统属性(例如“cn”)有效。
IIS设置完全相同,但这可能无关紧要,因为绑定过程有效。域成员资格(我阅读了各种各样的线程)并没有改变,也没关系,因为它是一个目录,我正在使用专用的用户进行绑定。
我 可以对属性进行过滤(参见上文)并查看 所有属性的 名称 。网络跟踪向我显示属性和它们的值是通过线路传输的,所以我需要的就是那里。使用像JXplorer这样的LDAP浏览器向我展示了完整的DirectoryEntry(包括值)..但是我的C#代码与它不相符。我对它为什么在一台虚拟机而不是另一台虚拟机上工作感到困惑。
我对所有数据都通过网络传输这一事实很感兴趣(因此这里的目录肯定没有权限问题)但是我的C#代码无法从中提取值:(
答案 0 :(得分:1)
我知道这是一个古老的问题,但是因为我对同一件事情大肆宣传,我认为对于那些已经走到这一步的人来说这是值得的......
问题在于DirectoryServices缓存模式的方式,如果它尝试加载自定义属性(DirectoryServices通过其连接的域不熟悉的任何属性) (专门针对Windows 8/2012的修补程序)
它实际上记录在知识库文章中 http://support.microsoft.com/kb/2802148还包含应该解决您问题的修补程序(如果您还没有解决它)
答案 1 :(得分:0)
是否有可能在两个不同的VM上以不同的用户身份运行?在哪种情况下可能的权限问题?第二个VM上的用户是否具有足够的权限?