 |
|
สอบถามเรื่อง path ของ LDAP ครับ ผมจะรู้ได้ยังไงว่าจะต้องใส่ Path อย่างไร |
|
 |
|
|
 |
 |
|
คือผมต้องการสร้าง login ผ่าน AD พัฒนาด้วย c# แต่ผมรู้แค่ IP และ port ของ server
ในส่วนของ path ผมไม่รู้ว่าต้องใส่อะไรครับ
แต่ผมเคย set ad ให้กับโปรแกรมๆนึง แค่ระบุ Host and port และใส่
Binding Credentials (ตรงนี้เป็น user pwd ของ admin)
ก็ใช้งานได้แล้ว โดยผลก็จะได้ เป็นโฟรเดอร์ต่างๆ เช่น Users , System , Program Data , .....
แต่ที่ผมต้องการตรวจสอบจะอยู่ใน Users ครับ
แต่ผมมาเขียน code โดยใส่แค่ Host and port มันติด error Unknown error (0x80005000) ครับ ด้านล่างเป็น code ที่เขียนครับ
แต่ถ้าผมกำหนด LDAPPATH = @"LDAP://192.168.1.66:389/dc=Users";
จะ error = A referral was returned from the server. ครับ
Code
private const String LDAPPATH = @"LDAP://192.168.1.66:389/";
public static Boolean AuthenticateUser(string username, string password)
{
DirectoryEntry entry = new DirectoryEntry(LDAPPATH, username, password);
try
{
Object obj = entry.NativeObject; //error Unknown error (0x80005000)
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
}
catch (Exception ex)
{
throw new Exception("Error authenticating user." + ex.Message);
}
return true;
}
Tag : .NET, Web (ASP.NET), C#, VS 2010 (.NET 4.x), VS 2012 (.NET 4.x), Windows
|
|
 |
 |
 |
 |
Date :
2013-08-19 08:33:19 |
By :
N |
View :
3334 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
path ให้เข้าไปดูใน AD ครับ จะเป็นชื่อตามด้วย local แบบนี้อ่ะครับ entry.Path = "LDAP://192.168.4.230/DC=edudemo,DC=local";
ลองลง VM และเทศ AD กะเครื่องตัวเองก้อได้
LDAPPATH = @"LDAP://192.168.1.66:389/dc=Users"; ===> User ในที่นี้ของคุณมันคือเช็ค Login ระบุ Path เข้า OU ครับ
ถ้าระบุเข้าถึง OU จะเป็น หลังมาหน้าประมาณนี้ entry.Path = "LDAP://192.168.4.125/OU=Students,DC=edudemo,DC=local";
[headประมาณนี้อ่ะ ของผม เช็ค AD ที่ Attribute บัตรประชาชนแลดึงข้อมูลจาก SQL Server[/head]
DirectoryEntry entry = new DirectoryEntry();
entry.Path = "LDAP://192.168.4.125/OU=Students,DC=edudemo,DC=local";
entry.Username = "administrator";
entry.Password = "password@1";
try
{
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(&(objectclass=user)(description=" +txtCitizen_Id.Text + "))";
SearchResult result = searcher.FindOne();
if (result != null)
{
DirectoryEntry userEntry = result.GetDirectoryEntry();
string firstname = userEntry.Properties["givenName"].Value.ToString();
string lastname = userEntry.Properties["sn"].Value.ToString();
try
{
object obj = entry.NativeObject;
Session["Username"] = txtCitizen_Id.Text.Trim();
Response.Redirect("Student_Profile.aspx");
}
catch (Exception ex)
{
Response.Write("authen fail");
}
}
else
{
lblStatus.Text = "ไม่มีข้อมูลบัตรประชาชน";
lblStatus.ForeColor = System.Drawing.Color.Red;
}
}
catch (Exception ex)
{
Response.Write("authen fail");
}
|
 |
 |
 |
 |
Date :
2013-08-21 18:54:26 |
By :
offonepoint |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ถนัด C#
Public Shared Function ValidateDomainUser(ByVal username As String, ByVal password As String) As Boolean
Try
Dim dm As Domain = Domain.GetCurrentDomain()
Dim de As New DirectoryEntry(dm.GetDirectoryEntry.Path, username, password, AuthenticationTypes.Secure)
Dim st As String = de.NativeGuid
Return True
Catch ex As Exception
End Try
Return False
End Function
|
ประวัติการแก้ไข 2013-08-22 12:41:17
 |
 |
 |
 |
Date :
2013-08-22 12:40:15 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|