Click here to Skip to main content
15,906,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am creating web application in which I am validating active directory user id and passwords to login to application. I am getting username from directory server. I am also want directory/group name in which user is placed like in my case users are placed within country folder. for example

domin name>>Country>>India>> Users
domin name>>Country>>US>> Users
domin name>>Country>>Canda>> Users

pl. help . I want to capture country name

What I have tried:

Private Function ValidateActiveDirectoryLogin(ByVal Domain As String, ByVal Username As String, ByVal Password As String) As Boolean
        Dim Success As Boolean = False
        Dim Entry As New System.DirectoryServices.DirectoryEntry("LDAP://" & Domain, Username, Password)
        Dim Searcher As New System.DirectoryServices.DirectorySearcher(Entry)
        Searcher.SearchScope = DirectoryServices.SearchScope.Subtree
        Try
            Dim Results As System.DirectoryServices.SearchResult = Searcher.FindOne
            Success = Not (Results Is Nothing)
            Dim dirSearcher As System.DirectoryServices.DirectorySearcher
            dirSearcher = New System.DirectoryServices.DirectorySearcher(Entry)
            dirSearcher.Filter = "(samAccountName=" & Username & ")"
            Dim sr As DirectoryServices.SearchResult = dirSearcher.FindOne()
            Dim de As System.DirectoryServices.DirectoryEntry = sr.GetDirectoryEntry()
            Dim userFirstName = de.Properties("GivenName").Value.ToString()
            Dim userLastName = de.Properties("sn").Value.ToString()
            Dim group = de.Properties("MemberOf").Value.ToString()
            Session("username") = userFirstName + " " + userLastName

            Response.Redirect("Home.aspx")
        Catch
            Success = False
        End Try
        Return Success

    End Function
Posted

1 solution

Got my problem solution through just one line.

Dim pathParts As String() = sr.Path.Split(New Char() {","c, " "c})
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900