0
我花了整整一天,什么都没有。我正在开发一个使用域用户/密码进行身份验证的Web应用程序。代码被遵循。上半场没问题,我可以输出:“用户和传球是:真。”C#,UserPrincipal.FindByIdentity总是抛出异常:“服务器发送引用程序”或未知0x80005000
然后,UserPrincipal.FindByIdentity抛出错误,“服务器发送引用者”或“未知0x80005000”。我改变了连接参数多次,如: LDAP:// CN =用户,DC = SBI,DC = COM
CN =用户,DC = SBI,DC = COM
DC = SBI,DC = com
对于其中的每一个,上半部分代码是正确的,我可以让我的用户/通过成功验证。但我无法获得userPrincipal。
我GOOGLE了很多,但仍然没有得到,有人请帮助。
bool valid = false;
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "sbi.com", "LDAP://CN=Users,DC=sbi,DC=com"))
{
valid = context.ValidateCredentials(user, pass);
System.Diagnostics.Debug.WriteLine("the user and pass is: " + valid.ToString());
}
//return;
if (valid)
{
PrincipalContext context2 = new PrincipalContext(ContextType.Domain,
"sbi.com", "CN=Users,DC=sbi,DC=com",
ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing,
user, pass);
//System.Diagnostics.Debug.WriteLine("connected server:" + context2.ConnectedServer);
UserPrincipal userInDomain = UserPrincipal.FindByIdentity(context2, user);
if (userInDomain != null)
{
System.Diagnostics.Debug.WriteLine("user found: " + userInDomain.Name);
}
else
{
System.Diagnostics.Debug.WriteLine("user not found");
}
}
为什么你重新创建上下文?使用FindByIdentity的第一个上下文更简单。我怀疑这个标志(即Signing,Negotiate,ecc)可能会产生错误。例如密封只能用于Kerberos。检查此链接http://msdn.microsoft.com/en-US/library/system.directoryservices.accountmanagement.contextoptions.aspx – Max
谢谢Max,我重新创建,因为方法userPrincipal.FindByIdentity需要验证的用户。这不是问题,因为即使我评论第一部分,其余部分仍会报告相同的错误。我也改变了国旗或不指定它,仍然没有运气。 MSDN说,如果“容器”有一些错误,它可能会报告PrincipalOperationException,这正是我得到的。但我不知道它是否是“容器”:sbi.com/DC=sbi,DC=com,有一些错误 – JimZ