且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#/ ASP.NET / AD - "指定的目录服务属性或值不存在"。

更新时间:2023-02-15 20:14:05

我已经打了一个这样的问题一次。这可能是因为你无法检索LDAP NativeObject 属性进行身份验证。如果异常的 obj对象= entry.NativeObject后立即抛出。呼叫,检查用户对域权限

I've hit an issue like this once. It may be because you can't retrieve LDAP NativeObject property for authentication. If the exception is thrown right after the object obj = entry.NativeObject; call, check if user has permissions on the domain.

通过您的code无论是调试,看它是否确实是NativeObject绑定失败。或者将一个try / catch块周围像下面的IsAuthenticated()函数的结合。您应该看到自定义错误抛出,如果它引起我所描述的问题。

Either debug through your code to see if it is indeed the NativeObject binding that is failing. Or Put a try/catch block around the binding in your IsAuthenticated() function like below. You should see the custom error thrown if it's caused by the issue I'm describing.

try
{   //Bind to the native AdsObject to force authentication.         
    Object obj = entry.NativeObject;
}
catch (System.Runtime.InteropServices.COMException e)
{
    if (e.ErrorCode == -2147016694) // -2147016694 - The specified directory service attribute or value does not exist.
    {
        throw new Exception("Can't retrieve LDAP NativeObject property");
    }
    throw;
}