如何连接到MVC 5中的本地LDAP服务器? [英] How to connect to local LDAP server in MVC 5 ?
问题描述
你好,
我正在尝试连接到我拥有的本地LDAP服务器使用Apache Directory Studio进行设置。我正在使用Visual Studio 2015企业更新2和MVC 5.
以下是我使用的两种方法:
public void ldap()
{
try
{
DirectoryEntry entry =新迪rectoryEntry(QUOT; LDAP://本地主机:10389");
DirectorySearcher mySearcher = new DirectorySearcher(entry);
var result = mySearcher.FindOne();
}
catch(System.Runtime.InteropServices.COMException)
{
System.Runtime.InteropServices.COMException异常= new System.Runtime.InteropServices.COMException( );
Console.WriteLine(exception);
}
catch(InvalidOperationException)
{
InvalidOperationException InvOpEx = new InvalidOperationException();
Console.WriteLine(InvOpEx.Message);
}
catch(NotSupportedException)
{
NotSupportedException NotSuppEx = new NotSupportedException();
Console.WriteLine(NotSuppEx.Message);
}
}
执行var result = mySearcher.FindOne()后,执行System.Runtime。 System.DirectoryServices.dll中出现"InteropServices.COMException",表示在调用COM-Component时传递了HRESULT E_FAIL错误。
我不知道这意味着什么使用Google找不到有用的东西。
2nd approach:
try
{
LdapConnection ldapConnection = new LdapConnection(" LDAP:// localhost:10389");
var networkCredential = new NetworkCredential(" ; cbrunato"," c2VjcmV0"," dc = example,dc = com");
ldapConnection.SessionOptions.SecureSocketLayer = true;
ldapConnection.SessionOptions.VerifyServerCertificate + = delegate {return true;} ;
ldapConnection.AuthType = AuthType.Negotiate;
ldapConnection.Bind(networkCredential);
}
catch(例外e)
{
Console.WriteLine (e.Message);
}
执行ldapConnection.Bind(networkCredential)后,我收到错误消息"LDAP服务器不可用"。
当我停止ldap服务器并运行程序时,我得到相同的错误,所以我想我没有得到与我的ldap服务器的连接两种方法,但我没有提示为什么。
我非常感谢任何帮助。
执行var result = mySearcher.FindOne()后,System.DirectoryServices.dll中出现System.Runtime.InteropServices.COMException',表示在调用COM组件时传递了HRESULT E_FAIL错误。
我不知道这意味着什么并且没有找到有用的东西。
这是事情的运作方式  ;在.NET之前,MS Windows O / S平台上的许多解决方案仍然基于COM解决方案。
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680573(v = vs.85)的.aspx
https://msdn.microsoft.com/en-us/library/system.runtime.interopservices(v = vs.90).aspx
Hello,
I´m trying to connect to an local LDAP server which i have set up using Apache Directory Studio. I´m using Visual Studio 2015 enterprise update 2 and MVC 5.
These are the two approaches I´m working with:
public void ldap()
{
try
{
DirectoryEntry entry = new DirectoryEntry("LDAP://localhost:10389");
DirectorySearcher mySearcher = new DirectorySearcher(entry);
var result = mySearcher.FindOne();
}
catch (System.Runtime.InteropServices.COMException)
{
System.Runtime.InteropServices.COMException exception = new System.Runtime.InteropServices.COMException();
Console.WriteLine(exception);
}
catch (InvalidOperationException)
{
InvalidOperationException InvOpEx = new InvalidOperationException();
Console.WriteLine(InvOpEx.Message);
}
catch (NotSupportedException)
{
NotSupportedException NotSuppEx = new NotSupportedException();
Console.WriteLine(NotSuppEx.Message);
}
}
After var result = mySearcher.FindOne() is executed, an System.Runtime.InteropServices.COMException' in System.DirectoryServices.dll occures, stating that an HRESULT E_FAIL-error was passed when calling a COM-Component.
I have no idea what that means and didn´t find something helpful using Google.
2nd approach:
try
{
LdapConnection ldapConnection = new LdapConnection("LDAP://localhost:10389");
var networkCredential = new NetworkCredential("cbrunato", "c2VjcmV0", "dc=example,dc=com");
ldapConnection.SessionOptions.SecureSocketLayer = true;
ldapConnection.SessionOptions.VerifyServerCertificate += delegate { return true; };
ldapConnection.AuthType = AuthType.Negotiate;
ldapConnection.Bind(networkCredential);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
After ldapConnection.Bind(networkCredential) is executed, i get the error message "LDAP server is not available".
When i stop the ldap Server and run the program i get the same errors, so i guess i don´t get a connection to my ldap server with both approaches, but i have no clue why.
I´m very thankful for any help.
After var result = mySearcher.FindOne() is executed, an System.Runtime.InteropServices.COMException' in System.DirectoryServices.dll occures, stating that an HRESULT E_FAIL-error was passed when calling a COM-Component.I have no idea what that means and didn´t find something helpful using Google.
It's how things worked before .NET and many solutions on the MS Windows O/S platform are still based on COM solutions.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680573(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/system.runtime.interopservices(v=vs.90).aspx
这篇关于如何连接到MVC 5中的本地LDAP服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!