How to know if my DirectoryEntry is really connected to my LDAP directory?

前端 未结 4 617
猫巷女王i
猫巷女王i 2020-12-20 16:48

I\'m connecting to a LDAP directory in C#, so I\'ve used the DirectoryEntry class.

When you do the \"new DirectoryEntry\" with address, login, and password it is sup

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-20 17:50

    Just "newing" up a DirectoryEntry does NOT create a connection to the LDAP store.

    Only once you start using its properties, or when you access the .NativeObject property explicitly, you'll actually get a connection to the LDAP store.

    In order to make sure you're connected, just read out the (DirectoryEntry).NativeObject in a try...catch clause - if it bombs out, you have a problem, otherwise your connection is now up and active.

    Unfortunately, to my knowledge, there is no property or method you can call to figure out whether or not you've successfully connected to LDAP using DirectoryEntry.

    Marc

提交回复
热议问题