• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

I would like to pull the name of the user from the ldap for security authentication in VB.NET

I have built an application using VB.NET.For user Authentication, when the user tries to open the application, I should be able to store the windows net work passowrd and authenticate it with our ldap authentication.Could you please tell me how I can acheive this?

Thanks,
0
g46905
Asked:
g46905
  • 8
  • 7
1 Solution
 
g46905Author Commented:
I found the following code to be useful for what I am trying to acheive.I have few questions so that I can customize the code as per my requirement.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21248005.html


In the code below,

1. How can I get the login name?
2.How do I know the IP address?
3. What did  "givenname" and "sc" refer to?

Please keep in mind that I am relatively new to VB.NET

Ok, this is the answer.

If you want to search based on "User logon name (pre-Windows 2000)", use sAMAccountName attribute in the ldap query filter.

Dim ldapPath As String = "LDAP://192.168.1.110/OU=ARCS Users,DC=arcs,DC=acmc,DC=local"
Dim filter As String = String.Format("(&(objectClass=user)(objectCategory=person)(sAMAccountName={0}))", loginName)

Dim entry As New DirectoryEntry(ldapPath)
Dim searcher As New DirectorySearcher(entry, filter, New String() {"givenName", "sn"})
Dim fullName As String
Try

    Dim result As SearchResult = searcher.FindOne()
    If Not IsNothing(result) Then
     If Not IsNothing(result.Properties("givenName")) Then
         fullName = result.Properties("givenName")(0)
     End If
     If Not IsNothing(result.Properties("sn")) Then
         fullName += " " + result.Properties("sn")(0)
     End If
    End If

Catch
    Throw
Finally
    If Not IsNothing(entry) Then
     entry.Dispose()
    End If
    If Not IsNothing(searcher) Then
     searcher.Dispose()
    End If
End Try
0
 
g46905Author Commented:
After some research,
                               I have learned that we will need DirectoryEntry and DirectorySearcher objects. Do you know which DLL they belong to? I found a very similar code for ASP .Net, and such objects are available in System.DirectoryServices NameSpace, which is not available in a windows aplication, but available in a Web Application only.I am currently working on Windows Application and not Web Application.Could you please tell the NameSpace that is available in Windows application to acheive the goal of Ldap authentication? Thanks  for your help
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ihenryCommented:
>> 1. How can I get the login name?
>> 2.How do I know the IP address?
Since you're working  on Windows app, you can ignore that if you run the app "inside your domain".

And the following code can help you to build the ldap path

        Dim root As New DirectoryEntry
        root.Path = "LDAP://rootDSE"
        Dim dnsHost As String = DirectCast(root.Properties("defaultNamingContext").Value, String)
        Dim ldapPath As String = String.Format("LDAP://{0}", dnsHost)

>> 3. What did  "givenname" and "sc" refer to?
givenName = first name
sn = surname

>> Could you please tell the NameSpace that is...
You need to reference to System.DirectoryServices.dll.
0
 
g46905Author Commented:
Can I use the same reference ever for my VB.NET ( Windows and not WEb application ) ?

Thanks
0
 
ihenryCommented:
It doesn't matter whether you're working on Windows or Web application, the reference isn't added by default and you have to add it yourself.
0
 
g46905Author Commented:
I reason why I was asking this is because when I type in Imports System. in my Visual Studio .NET , I would expect to show
  DirectoryServices.dll iin the drop down list for me to select.

Thanks
0
 
g46905Author Commented:
Could you please try this on in your application and let me know if you are able to view  the list of objects under System. Name Space?

Thanks,
0
 
ihenryCommented:
I guess you didn't do this

1. Right click on the "References" node in the VS.NET solution explorer.
2. Select "Add Reference", the "Add Reference" dialog window opens.
3. Under ".NET" tab, find and select System.DirectoryServices.dll.
4. Press "Select" button
5. Press Ok button

0
 
g46905Author Commented:
Thanks expert.By following the steps mentioned above, I was able add the referece to my Project.Coming back to our question, I used the code to build the path and I am gettig "root not declared" .Can you please help me?

And the following code can help you to build the ldap path

        Dim root As New DirectoryEntry
        root.Path = "LDAP://rootDSE"
        Dim dnsHost As String = DirectCast(root.Properties("defaultNamingContext").Value, String)
        Dim ldapPath As String = String.Format("LDAP://{0}", dnsHost)

Thanks,

0
 
ihenryCommented:
Compile?  if it's run-time error please post the exception stack trace?
0
 
ihenryCommented:
Typo in my previous question. It should be, was it compile error or run-time error? sorry for the confusion.
0
 
ihenryCommented:
@g46905, hows the problem so far?
0
 
g46905Author Commented:
I am still working on implementing the class you suggested.I will let you know once I am there.Thanks for your concern.

Thanks
0
 
g46905Author Commented:
Ihenry,
         I have worked with the implementation of the ldap and it looks loke I am headign towards the right direction.However, I would like to store all the values in the ldap table locally andI am not sure how to do this in VB.NET.I had a similar situation whe nI was working with JAVA and I believe I used Vector( if you are familiar with it ) .My mind is blank with it comes to VB.NET.Could you please give me your valuable suggestion/help.Please let me know if this is not related or need more points.

Thanks,
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now