สอบถามวิธีการใช้ .net connect to solaris ldap มีวิธีconnectอย่างไรบ้างครับ
Code (C#)
<%@ Assembly Name="System.DirectoryServices, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>
<%@ Import Namespace="System.DirectoryServices"%>
<%@ Import Namespace="System.Security.Cryptography"%>
<%@ Import Namespace="System.Text"%>
<%@ Page Language="C#" %>
<script runat="server">
string initLDAPPath = "dc=tc, dc=thaicreate, dc=com";
string initLDAPServer = "192.168.0.5";
string initShortDomainName = "tc";
string strErrMsg;
public string MD5(string strString) {
ASCIIEncoding ASCIIenc = new ASCIIEncoding();
string strReturn;
byte[] ByteSourceText = ASCIIenc.GetBytes(strString);
MD5CryptoServiceProvider Md5Hash = new MD5CryptoServiceProvider();
byte[] ByteHash = Md5Hash.ComputeHash(ByteSourceText);
strReturn = "";
foreach (byte b in ByteHash) {
strReturn = (strReturn + b.ToString("x2"));
}
return strReturn;
}
void Page_Load(object sender, EventArgs e) {
}
protected void btnLogin_Click(object sender, System.EventArgs e) {
string DomainAndUsername = "";
string strCommu;
bool flgLogin = false;
strCommu = ("LDAP://"
+ (initLDAPServer + ("/" + initLDAPPath)));
DomainAndUsername = (initShortDomainName + ("\\" + txtUser.Text));
DirectoryEntry entry = new DirectoryEntry(strCommu, DomainAndUsername, txtPwd.Text);
object obj;
try {
obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
SearchResult result;
search.Filter = ("(SAMAccountName="
+ (txtUser.Text + ")"));
search.PropertiesToLoad.Add("cn");
result = search.FindOne();
if ((result == null)) {
flgLogin = false;
strErrMsg = "Please check user/password";
}
else {
flgLogin = true;
}
}
catch (Exception ex) {
flgLogin = false;
strErrMsg = "Please check user/password";
}
if ((flgLogin == true)) {
this.lbDisplay.Text = ("Welcome " + txtUser.Text);
}
else {
this.lbDisplay.Text = strErrMsg;
}
}
</script>
<html>
<head>
<title>ThaiCreate.Com</title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtUser" runat="server" Width="147px"></asp:TextBox>
<asp:TextBox ID="txtPwd" runat="server" Width="147px" TextMode="Password"></asp:TextBox>
<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />
<br />
<asp:Label ID="lbDisplay" runat="server"></asp:Label>
</form>
</body>
</HTML>
ลองดู Code ตัวนี้หรือยังครับ
Go to : (C#) ASP.NET User Authentication Active Directory (AD)
Date :
2011-06-05 09:27:14
By :
webmaster
ลองแล้วครับ แต่ขึ้นError : The specified domain either does not exist or could not be contacted.
path เป็นแบบนี้ครับ ou=people,o=ttt.co.th,o=aaa ไม่แน่จะระบุถูกไม่ครับ
EX.
Code (VB.NET)
Dim dirEntry As New DirectoryEntry("ldap://192.168.1.2:602/ou=people,o=ttt.co.th,o=aaa")
Date :
2011-06-05 14:45:56
By :
fight
อยากทราบว่า usernameและpassword ที่ใส่ คือเป็นของตัวADหรือLdap ใช่ไมครับ
Date :
2011-06-06 19:53:32
By :
fight
Load balance : Server 02