Ldap连接抛出对象引用未设置为对象错误的实例

时间:2014-10-25 06:24:08

标签: c# asp.net .net ldap

Ldap连接抛出对象引用未设置为对象错误的实例

我正在尝试连接到LDAP以验证用户身份。这是我的代码,在将connction安全套接字层设置为true后,我在connection.connect期间遇到异常。

它抛出的异常对象引用未设置为对象的实例,我已创建了连接对象,但不知道出了什么问题。有人帮帮我吗?

using LdapConnection = Novell.Directory.Ldap.LdapConnection;
using LdapException = Novell.Directory.Ldap.LdapException;

 var ldapHost = WebConfigurationManager.AppSettings["LDAP_HOST"];
 var ldapPort = WebConfigurationManager.AppSettings["LDAP_PORT"];

 var connection = new LdapConnection {SecureSocketLayer = true};
 connection.Connect(ldapHost, Convert.ToInt32(ldapPort)); // Getting exception here object reference not set to an instance of an object.

 sb = new StringBuilder();
 sb.Append(ldapLocation).Append(userName).Append(",").Append(ldapLocationIndia);
 connection.Bind(LdapConnection.Ldap_V3, sb.ToString(), password);  

请提前帮助,谢谢。

stacktrace info:

在Novell.Directory.Ldap.Connection.connect(String host,Int32 port,Int32 semaphoreId)    在Novell.Directory.Ldap.Connection.connect(字符串主机,Int32端口)    在Novell.Directory.Ldap.LdapConnection.Connect(String host,Int32 port)    在C:\ Project \ Production Version 2.0 \ Planner \ Planner \ Controllers \ AccountController.cs中的Planner.Controllers.AccountController.isAuthenticated(LoginModel模型):第106行    在C:\ Project \ Production Version 2.0 \ Planner \ Planner \ Controllers \ AccountController.cs中的Planner.Controllers.AccountController.Login(LoginModel模型):第44行    在lambda_method(Closure,ControllerBase,Object [])    在System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,Object []参数)    在System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary 2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary 2个参数)    在System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeSynchronousActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary 2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8 1.b__7(IAsyncResult _)    在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()    在System.Web.Mvc.Async.AsyncResultWrapper.End [TResult](IAsyncResult asyncResult,Object tag)    在System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)    在System.Web.Mvc.Async.AsyncControllerActionInvoker。&lt;&gt; c__DisplayClass37。&lt;&gt; c__DisplayClass39.b__33()    在System.Web.Mvc.Async.AsyncControllerActionInvoker。&lt;&gt; c__DisplayClass4f.b__49()

1 个答案:

答案 0 :(得分:1)

您的配置中是否正确设置了ldapHostldapPort

connection.connect()抛出的异常是tpye LDAPException,所以我认为它甚至没有尝试连接。