C# JavaLDAP身份验证工作正常,Csharp没有,我做错了什么?
我有下面的Java程序可以运行,用真实的IP地址、用户名和密码填充以下伪值:C# JavaLDAP身份验证工作正常,Csharp没有,我做错了什么?,c#,ldap,C#,Ldap,我有下面的Java程序可以运行,用真实的IP地址、用户名和密码填充以下伪值: package com.mycom; import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; public class Main { public static void main(String ... args) { Main main = new Main();
package com.mycom;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Main
{
public static void main(String ... args)
{
Main main = new Main();
main.go();
}
public void go()
{
Hashtable<String, Object> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "LDAPS://1.2.3.4:636/o=Some%20University"); // obviously I use a real IP address
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid=jblow, ou=People, o=Some University");
env.put(Context.SECURITY_CREDENTIALS, "BigTeamFanPassword");
try
{
Context context = new InitialContext(env);
System.out.println("no exceptions...");
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
}
我尝试过各种方法,比如在主机字符串中的端口号后面放上带有“/o=org”的组织,等等,我已经厌倦了反复尝试。有人能告诉我这里出了什么问题吗?有什么例外?哦,对不起--“LDAP服务器不可用”
using System;
using System.DirectoryServices.Protocols;
using System.Net;
namespace LdapTesting
{
class Program
{
static void Main(string[] args)
{
string host = "LDAPS://1.2.3.4:636";
using (LdapConnection con = new LdapConnection(host))
{
con.SessionOptions.SecureSocketLayer = true;
con.SessionOptions.ProtocolVersion = 3;
con.Credential = new NetworkCredential("uid=jblow", "BigTeamFanPassword", "ou=People, o=Some University");
con.AuthType = AuthType.Basic;
try
{
con.Bind();
Console.WriteLine("No exception");
}
catch (Exception e)
{
Console.WriteLine("exception, " + e.Message);
}
}
}
}
}