I am getting "No Overload For Method 'Bind' takes '2' Arguments" under this line:
try
{
con.Bind(userDN, userPasswd);
}
Please help.Below is the full code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Diagnostics;
using System.DirectoryServices.Protocols;
using System.DirectoryServices;
namespace edirectory_test_1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string userDN = "cn=proxy" + ",o=University";
string userPasswd = "test101";
LdapConnection con = new LdapConnection(new LdapDirectoryIdentifier("11.13.220.33:389"));
con.Credential = new NetworkCredential(String.Empty, String.Empty);
con.AuthType = AuthType.Basic;
using (con)
{
try
{
con.Bind(userDN, userPasswd);
}
catch (LdapException)
{
lblResult.Text = "Invalid server address or admin password";
return;
}
catch (DirectoryOperationException)
{
lblResult.Text = "Invalid admin username";
return;
}
try
{
SearchRequest request = new SearchRequest("o=campus", "(&(objectClass=Person)(uid=" + Login1.UserName + "))", SearchScope.Subtree);
SearchResponse response = (SearchResponse)con.SendRequest(request);
if (response.Entries.Count == 0)
{
lblResult.Text = "No such username.";
return;
}
else
{
SearchResultEntry entry = response.Entries[0];
string dn = entry.DistinguishedName;
con.Credential = new NetworkCredential(dn, Login1.Password);
con.Bind();
// If we get this far without an exception, the username and
// password are valid. We can now use a SearchRequest to search
// for group membership etc, but that's out of scope for this
// example.
e.Authenticated = true;
}
}
catch (DirectoryOperationException)
{
lblResult.Text = "Invalid root DN / search filter";
return;
}
catch (LdapException)
{
lblResult.Text = "Invalid password";
return;
}
catch (Exception ex)
{
// an LdapException is thrown if the password is invalid, with
// ex.Message == "The supplied credential is invalid.".
lblResult.Text = ex.Message;
}
}
}
}
}
spyxdaxworld
Member
431 Points
232 Posts
No Overload For Method 'Bind' takes '2' Arguments .
Jan 12, 2012 06:28 PM|LINK
I am getting "No Overload For Method 'Bind' takes '2' Arguments" under this line:
try
{
con.Bind(userDN, userPasswd);
}
Please help.Below is the full code:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.Diagnostics; using System.DirectoryServices.Protocols; using System.DirectoryServices; namespace edirectory_test_1 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { string userDN = "cn=proxy" + ",o=University"; string userPasswd = "test101"; LdapConnection con = new LdapConnection(new LdapDirectoryIdentifier("11.13.220.33:389")); con.Credential = new NetworkCredential(String.Empty, String.Empty); con.AuthType = AuthType.Basic; using (con) { try { con.Bind(userDN, userPasswd); } catch (LdapException) { lblResult.Text = "Invalid server address or admin password"; return; } catch (DirectoryOperationException) { lblResult.Text = "Invalid admin username"; return; } try { SearchRequest request = new SearchRequest("o=campus", "(&(objectClass=Person)(uid=" + Login1.UserName + "))", SearchScope.Subtree); SearchResponse response = (SearchResponse)con.SendRequest(request); if (response.Entries.Count == 0) { lblResult.Text = "No such username."; return; } else { SearchResultEntry entry = response.Entries[0]; string dn = entry.DistinguishedName; con.Credential = new NetworkCredential(dn, Login1.Password); con.Bind(); // If we get this far without an exception, the username and // password are valid. We can now use a SearchRequest to search // for group membership etc, but that's out of scope for this // example. e.Authenticated = true; } } catch (DirectoryOperationException) { lblResult.Text = "Invalid root DN / search filter"; return; } catch (LdapException) { lblResult.Text = "Invalid password"; return; } catch (Exception ex) { // an LdapException is thrown if the password is invalid, with // ex.Message == "The supplied credential is invalid.". lblResult.Text = ex.Message; } } } } }