 |
|
ถามเรื่อง การใช้งาน ASP.NET กับ Authentication ผ่าน AD ครับ |
|
 |
|
|
 |
 |
|
version เดียวกันครับ
|
 |
 |
 |
 |
Date :
2011-09-23 09:35:40 |
By :
kurono |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สำหรับบางบริษัท
ผู้ดูแลระบบ ได้กำหนดผู้ใช้ ให้ใช้งานคอมพิวเตอร์เฉพาะเครื่องที่ระบุไว้
เช่น user1 สามารถ Login ได้เฉพาะคอมพิวเตอร์ pc1 จะไม่สามารถ Login ที่ pc2 ได้
ไม่ทราบว่าของคุณเป็นเช่นนั้นหรือไม่
|
 |
 |
 |
 |
Date :
2011-09-23 10:02:03 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ยังไม่สะดวกถามทาง admin ที่ดู server น่ะครับ
แต่ก่อนหน้านี้เป็น asp ก็ยิงไป AD ได้ปกตินะครับ มาติดตอนเปลี่ยนมาเป็น .net นี่แหละครับ
|
 |
 |
 |
 |
Date :
2011-09-23 12:01:50 |
By :
kurono |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1. ทราบว่า ลองที่เครื่องตัวเอง แล้วผ่าน
งั้นให้ลองที่เครื่องตัวเองใหม่ แต่ให้ User อื่นมาทดสอบว่าผ่านหรือไม่
2. ผมเจอปัญหาอย่าง No3 กับ asp.net แต่กับ php ไม่มีปัญหา
|
 |
 |
 |
 |
Date :
2011-09-23 12:10:58 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1. ลองที่เครื่องผมเองได้หมดทุก user ครับ
2. ถ้าเป็นที่ตัว asp.net ผมสามารถไป config ที่ iis ให้มันไปที่ AD ได้ไหมครับ จะไปลองกับ server test ดูก่อนน่ะครับ(server test ก็ไม่ได้เหมือนกันครับ)
|
 |
 |
 |
 |
Date :
2011-09-23 13:52:38 |
By :
kurono |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าทำได้แล้ว
แจ้งด้วยนะขอรับ
ผมก็อยากรู้เฉลยของปัญหาเรื่องนี้เหมือนกัน
|
 |
 |
 |
 |
Date :
2011-09-23 17:07:20 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เช่นเดียวกันครับ
Cheer !! 
|
 |
 |
 |
 |
Date :
2011-09-23 17:20:31 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Imports System.Text
Imports System.Collections
Imports System.DirectoryServices
Namespace FormsAuth
Public Class LdapAuthentication
Private _path As String
Private _filterAttribute As String
Public Sub New(path As String)
_path = path
End Sub
Public Function IsAuthenticated(domain As String, username As String, pwd As String) As Boolean
Dim domainAndUsername As String = domain & "\" & username
Dim entry As New DirectoryEntry(_path, domainAndUsername, pwd)
Try
'Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObject
Dim search As New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" & username & ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If result Is Nothing Then
Return False
End If
'Update the new path to the user in the directory.
_path = result.Path
_filterAttribute = DirectCast(result.Properties("cn")(0), String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " & ex.Message)
End Try
Return True
End Function
Public Function GetGroups() As String
Dim search As New DirectorySearcher(_path)
search.Filter = "(cn=" & _filterAttribute & ")"
search.PropertiesToLoad.Add("memberOf")
Dim groupNames As New StringBuilder()
Try
Dim result As SearchResult = search.FindOne()
Dim propertyCount As Integer = result.Properties("memberOf").Count
Dim dn As String
Dim equalsIndex As Integer, commaIndex As Integer
For propertyCounter As Integer = 0 To propertyCount - 1
dn = DirectCast(result.Properties("memberOf")(propertyCounter), String)
equalsIndex = dn.IndexOf("=", 1)
commaIndex = dn.IndexOf(",", 1)
If -1 = equalsIndex Then
Return Nothing
End If
groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1))
groupNames.Append("|")
Next
Catch ex As Exception
Throw New Exception("Error obtaining group names. " & ex.Message)
End Try
Return groupNames.ToString()
End Function
End Class
End Namespace
|
 |
 |
 |
 |
Date :
2011-12-15 13:31:16 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|