ldap身份验证后返回用户详细信息(asp.net vb)

时间:2012-05-15 15:39:05

标签: asp.net vb.net active-directory ldap

下午全部! 我正在尝试为我的客户端设置一个新的内部系统,他们坚持将登录与AD集成,这是有道理的,我已经设置了没问题。

然而,在身份验证之后,我还想要做的是将一些用户详细信息/属性存储为会话变量。

我有以下代码来验证用户:

'this function authenticates against AD - very simple and works nicely.
Function AuthenticateUser(path As String, user As String, pass As String) As Boolean
    Dim de As New DirectoryEntry(path, user, pass, AuthenticationTypes.Secure)
    Try
        'run a search using those credentials.  
        'If it returns anything, then you're authenticated
        Dim ds As DirectorySearcher = New DirectorySearcher(de)
        ds.FindOne()

        Return True
    Catch
        'otherwise, it will crash out so return false
        Return False
    End Try
End Function

效果很好,一旦函数返回True,我将Session(“LoggedIn”)设置为True。

我需要做的是(希望在上面的函数中)保存用户的名字,以及用户的AD配置文件中的其他2个自定义属性。

我如何访问这些(假设)

1 个答案:

答案 0 :(得分:1)

使用支持检索属性的DirectorySearcher构造函数。将LDAP客户端所需的属性添加到构造函数中。

另见