.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

Get Member from LDAP using C# 2.0

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

I'm currently writing a process where I need to determine if an User on my LDAP string is an Admin.

How can I accomplish this?  What would be the easy and quickest way?

I've been trying to use the code below..... Any feedback is greately appreciated. Tks



View Complete Post

More Related Resource Links

Combining two LDAP queries


Hey guys, I have these two queries I'd like to combine into one.  Is there any way of doing it?
Query 1: (&(!cn=SystemMailbox{*})(&(&(ou>="")(name=executive*)(objectCategory=organizationalUnit)(ou=*operations))))
Query 2: (&(!cn=SystemMailbox{*})(&(ou>="")(name=50*)))
Thanks in advance.

Hey guys, I have these two queries I'd like to combine into one.  Is there any way of doing it?


LDAP nested groups filter


Hi all,

In my organization we use nested groups.

For a particular usage, we have a group (let's assume that the group name "kuku"), and the names of all the nested groups under it contains "kuku" as well.

We may assume that no other group in the LDAP has "kuku" in the name.

I need to create a filter which will return all the users which belong to one of the "kuku"s group.

Obviously, using this filter will bring only the head kukus

(&(&(objectclass=user)(objectclass=person))(memberOf=CN=kuku,cn=.rest of the group DN.))

How can I use wild card to fetch all users which belong to any kuku?

For example: (&(&(objectclass=user)(objectclass=person))(memberOf=CN=.*kuku.*))



LDAP - Can't find server


Hey people,

I would like to get a persons name from their username - a common query on forums i know, but i haven't managed to get mine working yet and any help would be appreciated.

I currently have this code that I found here: http://www.vbforums.com/showthread.php?t=612655 (Thanks Chris128)

I have adapted it from VB into VB.net. The page renders but when i enter my username into the Username textBox and hit the submit button (Which calls IsUser) I just get "The specified domain either does not exist or could not be contacted." I have tried lots of other code but I always get this response...

If anyone can help by posting links to a tutorial or another post for code that they know works, i will give it a go.


Imports System.DirectoryServices

Partial Class UserInfo
    Inherits System.Web.UI.Page

    Private Function GetRealNameFromAd(ByVal UsernameToFind As String) As String
        Using searcher As New DirectorySearcher(New DirectoryEntry())
            searcher.PageSize = 1000
            searcher.SearchScope = SearchScope.Subtree
            searcher.Filter = "(&(samAccountType=805306368)(sAMAccountName=" & UsernameToFind & "))"
            Using Results A

Getting users list reporting to manager from LDAP


Dear All,

I need to get list of users reporting to a particular manager from the Active directory.

In the active directory there is manager property with contains the data in the following way.


Please help me in building the filter condition.

I am using the following

pUserName="Gegore Lid";

strSearch = "(&(objectClass=user)(objectCategory=user)((Manager cn=" + pUserName + "))";

DirectorySearcher dSearcher = new DirectorySearcher(dEntry, strSearch);

            //Account properites to load
            string[] arrPropertiesToLoad = { "displayName", "department", "manager", "sAMAccountName", "EmployeeNumber", "Title" };

          SearchResultCollection sResultColl = dSearcher.FindAll();

 the above code is not returning any result.

Please help me in this.



How to authenticate local user usin ldap or non domain authentication



I created one application, and I need to authenticate local user. This user is the user who is login to his/her Personal Computer.. Main thing his that he/she does not in any DOMAIN... I want NON-DOMAIN authentication.. any how.... please help...

help needed: Ldap User authentication using userDN and password



Is it possible to authenticate a user using userDN and password? If so, then tell me the syntax.So far i have tried to authenticate using username and password from my c# code using directoryentry which takes the parameters like domainname,username and password. But i need to authenticate using Userdn and password.

helped needed: ASP LDAP authentication failed in IE 8


I use the following code to do the user authentication through Active Directory using LDAP.

entry = new DirectoryEntry("LDAP://" + server, user_name, password);
if (!string.IsNullOrEmpty(entry.Name))
EmployeeNetId = entry.Username.Substring(0, 3);

// Retrieve EmployeeId, and Employee Full Name
EmployeeId = -1;

It works for Chrome, Firefox with no problem. But with IE 8, it works sometimes, and failed on some computers. When it failed, I figured that I need to check SSL 2.0 in IE 8 Internet Options.  It's weird because in those computers that IE 8 works, SSL 2.0 is also unchecked.

Am I using some deprecated method? Or How do I specifiy the SSL version options in the LDAP connection?

LDAP Problem with .NET - Unknown error (0x80005000)


I am trying to create a proof of concept to show how to connect to an LDAP
server and how to search for values but I do not get anywhere. Here is what I
have so far:

Dim objEntry As DirectoryEntry
Dim objSearcher As DirectorySearcher


objEntry = New DirectoryEntry("ldap://www.openldap.com/dc=OpenLDAP,dc=org",
Nothing, Nothing, AuthenticationTypes.Anonymous)

objSearcher = New DirectorySearcher(objEntry, "(ou=People)")
objSearchResult = objSearcher.FindOne()

If Not objSearchResult Is Nothing Then
'Do something
End If

Catch ex As Exception

result.Text = ex.Message & vbNewLine & ex.Source

End Try

My code fails at the line:
objSearchResult = objSearcher.FindOne()

with the unhelpfu error of Unknown error (0x80005000)

As you can see I use the www.openldap.com directory and I can connect
anonymously using the Softeerra LDAP Browser 2.5

Any help would be greatly appreciated 

PS: I know there is already a similar thread (http://forums.asp.net/thread/1028020.aspx) but none of the suggeste

Comparing Enum values in a collection - BC42025: Access of shared member, constant member, enum mem


I am upgrading from asp1.1 to 2.0

I use collection classes to sort data (e.g in datagrids etc)


Enum newsFields
End Enum

Public Overloads Sub Sort(ByVal sortField As newsFields, ByVal isAscending As Boolean)
Select Case sortField
Case newsFields.title

How to connect the OledbCommand object with another Member Function

protected void GridViewTest_RowDeleting(object sender, GridViewDeleteEventArgs e)
       int deleteKey = Int32.Parse(GridViewTest.DataKeys[e.RowIndex].Value.ToString());
       OleDbCommand deleteCommand = new OleDbCommand();
       deleteCommand.CommandType = CommandType.StoredProcedure();
           deleteCommand.Parameters.AddWithValue("@empid", deleteKey);
 private DataTable  Connection1(string Storedprocedure)
       using (OleDbConnection MyConnection = new OleDbConnection(ConfigurationManager.AppSettings[0].ToString()))
           OleDbDataAdapter MyAdapter = new OleDbDataAdapter(Storedprocedure, MyConnection);
           DataTable MyTable = new DataTable();
           return MyTable;

Hello Members,

           I need one help..I Don't know how to connect the command object with
another Member function...
I tried something in the above code...But i got error...Please put me in right direction...


'CrystalReportViewer1' is not a member of 'ReportViewer'


Hello, I added a CrystalReportViewer control to my ReportViewer page and when I try to set the CrystalReportViewer1.ReportSource in code I get the error "'CrystalReportViewer1' is not a member of 'ReportViewer'". 

I noticed that some of our older projects reference CrystalDecisions.ReportAppServer.ClientDoc but I am unable to find that dll anywhere on my machine so this project does not reference it. 

Any ideas?




From 3.5 to 2.0: No default member found for 'DataTable'



I'm trying to change the framework of an application I made a while from 3.5 back down to 2.0 as it's not compatible with the new server we put in (we're don't have permission to install 3.5 framework).

So, I went into the project properties and under the Compile tab, changed the project to 2.0. When I tried to publish the project I got a lot of errors and warnings and the publish failed.

In the 3.5 code, I had SQLSelect statement in a Dim which was labeled 'As DataTable'. When switching to 2.0, an error appears on the Dim saying: "Class 'System.Data.DataTable' cannot be indexed because it has no default property". So I simply took DataTable out of the code. Now, when I try to run the project, I get "No default member found for 'DataTable'.

Here's the code:

Function DisplayName(ByVal LoginName)

     Dim tempname(2) As String
     Dim signon As String

     tempname = Split(CheckUser(LoginName), "\")
     singon = tempname(1)

     Dim rst 'As DataTable
     rst = ExecSQLSelect("SELECT given_name, surname FROM ... etc")

     If rst.Rows.Count = 0 Then
          DisplayName = "Unknown"

          'This is where the error is:
          DisplayName = rst(0)("giv

Class member autocomplete


Is there in C# such feature as in VB when you create some class which inherits some interface and after clicking Enter after line Inherits SomeInterfaceHere all properties and functions which you need to inherit appear?

DataContractSerializer deserialization puzzle - by-pass member initialization.

Hi, I was using WCF and during the transmission of a object, of the type Book, see code below, the deserialization process throws a NullReferenceException. To isolate the problem, I uses a unit test like this rather than involving the full blown WCF marshalling. This appears to be solely a serialization/deserialization problem and has nothing to do with the communication issues in WCF. [Test] public void TestSerializeAndDeserializeBook() {     Book book = new Book( "Testing Serialization and Deserialization",                         new Person( 100, "Tom", "Smith" ),                         new Person( 101, "Peter", "Pan" ) );     DataContractSerializer ser = new DataContractSerializer( typeof(Book) );     using( Stream stm = new MemoryStream() )     {         ser.WriteObject( stm, book );         stm.Seek( 0, SeekOrigin.Begin );         Book regen = ser.ReadObject( stm ) as Book; // NullReferenceException here     &nb

Function retrieving users by country against (Active Directory) LDAP

Hello I've got such openquery SELECT * FROM Openquery(ADSI, 'SELECT EmployeeID, displayname, mailAddress, country FROM '' LDAP://MY-LDAP-PATH '' WHERE country=''coutry_code' '   ') country_code is 3 letters i think sth in format like USA, FRA etc I will need to retrieve users from up to 3 countries let say and i would like to create from this query above a stored procedure (or better a FUNCTION)  where someone calling a function can specify from which country does he/she wants to terieve users - when none country specified a function should retrieve users from all 3 let say. I'm not very advanced in programming in T-SQL yet so my question is -> can the variable be specified inside Openquery ? like for example SELECT * FROM Openquery(ADSI, 'SELECT EmployeeID, displayname, mailAddress, country FROM '' LDAP://MY-LDAP-PATH '' WHERE country=''@country' '   ') ACTIVE DIRECTORY HAS LIMITION OF RETRIEVING 1000 RECORDS AT ONCE - BUT NONE OF THESE COUNTRIES HAVE MORE THAN COUPLE HUNDREDS HOVWEVER summing them in one query this number of course will exceed 1000 recoreds so queries i think should be splitted and joined with union ??? Can anyone provide some example code of such function  The other problem i have is that openquery againt ADSI  above works correctly when i use SSMS localy on the server (connectin

LINQ to SQL compiler error CS1519: Invalid token 'void' in class, struct, or interface member decl

I get the following compiler errors when creating my first LINQ to SQL class (I just dragged a table "ProfileExtended" onto the designer and hit build):DataClasses.designer.cs(31,11): error CS1519: Invalid token 'void' in class, struct, or interface member declaration these are the offending lines of autogenerated code:#region Extensibility Method Definitions  partial void OnCreated();  partial void InsertProfileExtended(ProfileExtended instance);  partial void UpdateProfileExtended(ProfileExtended instance);  partial void DeleteProfileExtended(ProfileExtended instance);  #endregion

Can not figure out LDAP naming convention for AD Application Mode login

I am trying to configure Oracle Access Manager (OAM) with AD application mode (ADAM). I am being prompted for the administrator (root DN) LDAP login for the ADAM instance, and nothing I try works. I know the administrator account in ADAM, and when I installed ADAM I used this info for the partition information, CN=accessmanager, DC=devnet, DC=local , the local admin account is devadmin, which is in the administrators container. My question is, what should the LDAP naming convention I should use for devadmin ? Oracle's example is (cn=administrator,o=company,c=us), but nothing I tried seems to allow OAM to access the ADAM installation. The obvious CN=devadmin,DC=devnet,DC=local does not work. Thanks in advance, John  
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend