Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Active Directory Login failed when using C#

Posted on 2009-04-08
5
Medium Priority
?
1,226 Views
Last Modified: 2013-12-24
Hell experts!
I'm facing a weird problem when connection to AD using C#.
When I run the C# project, it fails and gives me an error saying that the user or password may be invalid.
I converted the code to VB.Net and it works perfectly.
The problem is ocurring when I call the FindOne method.
What could be causing this problem?
I've attached both c# and vb.net code to this message.

Please, help.
C# code:
 
            this.AD = new DirectoryEntry(loginPath, loginUsername, loginPassword);
            var filter = "(&(objectCategory=Person) (sAMAccountName=" + username + "))";
            var diretorySearcher = new DirectorySearcher(this.AD);
            SearchResult searchResult = null;
            diretorySearcher.SearchRoot = this.AD;
            diretorySearcher.SearchScope = SearchScope.Subtree;
            diretorySearcher.Filter = filter;
            searchResult = diretorySearcher.FindOne();
            DirectoryEntry user = searchResult.GetDirectoryEntry();
 
VB.Net code:
            Me.AD = New DirectoryEntry(loginPath, loginUsername, loginPassword)
            String filter = "(&(objectCategory=Person) (sAMAccountName=" & username & "))"
            DirectorySearcher diretorySearcher = New DirectorySearcher(Me.AD)
            SearchResult searchResult = Nothing
            diretorySearcher.SearchRoot = Me.AD
            diretorySearcher.SearchScope = SearchScope.Subtree
            diretorySearcher.Filter = filter
            searchResult = diretorySearcher.FindOne()
            DirectoryEntry user = searchResult.GetDirectoryEntry()

Open in new window

0
Comment
Question by:andrepires
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24104297
after the first line try this
object Native = this.AD.NativeObject;

Open in new window

0
 
LVL 2

Author Comment

by:andrepires
ID: 24106630
Ok, but what should I do with that Native object?
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24106757
nothing, that line basically tries to validate the entry against AD and makes connection with AD
0
 
LVL 2

Author Comment

by:andrepires
ID: 24106998
Ok... I'll try that and let you know.
Thanks.
0
 
LVL 2

Accepted Solution

by:
andrepires earned 0 total points
ID: 24208177
Hello.
The solution did not work.
I was forced to compile an assembly created with VB.Net and consume it in my application.
Thanks for helping!
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question