473,414 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Retrieve useraccount info from AD

Hi,

Does anyone have experience in retrieveing useraccount information like eg.
name, lastname, phonenumber, adress etc from Active Directory from an
asp.net application?

Perhaps standard components have already been developped to accomplish this
task?

Should I query the AD directly each time a request is made or should I
concider to replicate the AD information into a MS SQL database on a per day
basis to achieve the best performance possible and query the MS SQL database
instead?

Any help/links anything, would be appreciated.
Thank you

Kind regards
Torben
Nov 19 '05 #1
2 2172
I'm currently working on the same thing!

Have a look at this! It isn't 100% finished! If you make any improvements I
would like to see them!

Thanks

<TABLE id="tblGrids" cellSpacing="2" cellPadding="0" width="100%" border="0">
<TR>
<TD vAlign="top"><asp:Datagrid id="dgUsers" runat="server"
CssClass="Normal" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="4" Width="250px"
AutoGenerateColumns="False" PageSize="25"
AllowPaging="True">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"></asp:ButtonColumn>
<asp:BoundColumn DataField="Username" ReadOnly="True"
HeaderText="Name"></asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="Next >" PrevPageText="< Prev"
HorizontalAlign="Center" ForeColor="#330099"
BackColor="#FFFFCC" Mode="NumericPages"></PagerStyle>
</asp:Datagrid></TD>
<TD vAlign="top">
<P align="left">
<asp:Label id="lblUserName" runat="server" CssClass="strNormal"
Visible="False"></asp:Label></P>
<asp:Datagrid id="dgProps" runat="server" CssClass="Normal"
BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="4" Width="300px"
AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="PropertyName" ReadOnly="True"
HeaderText="Property"></asp:BoundColumn>
<asp:BoundColumn DataField="PropertyValue" ReadOnly="True"
HeaderText="Value"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099"
BackColor="#FFFFCC"></PagerStyle>
</asp:Datagrid></TD>
</TR>
</TABLE>
...::CodeBehind::..
Private Function CreateUserTable() As DataTable
Trace.Warn("ExtensionListing.aspx", "Called CreateTable()")
' create a datatable
Dim tblUsers As New DataTable("users")
With tblUsers
.Columns.Add("Username", System.Type.GetType("System.String"))
End With
ds.Tables.Add(tblUsers)
End Function

Private Sub LoadUserTable()
Trace.Warn("ExtensionListing.aspx", "Called LoadTable()")
' bind the data to the datagrid
Dim de As New
DirectoryEntry(ConfigurationSettings.AppSettings(" ActiveDirectoryPath"),
CustomAppSettings.GetAppSetting("ADUsername"),
CustomAppSettings.GetAppSetting("ADPassword"))
Dim src As New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=user))")
src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
src.Sort = New SortOption("Name", SortDirection.Ascending)
Dim res As SearchResult
CreateUserTable()
For Each res In src.FindAll
If InStr(res.Properties("Name")(0), ",") > 0 Then
Dim topRow As DataRow = ds.Tables("users").NewRow
topRow("Username") = Replace(res.Properties("Name")(0), "
(Email & Pager)", "")
ds.Tables("users").Rows.Add(topRow)
End If
Next

With dgUsers
.DataSource = ds.Tables("users")
.DataBind()
End With
End Sub

Private Function CreatePropsTable() As DataTable
Trace.Warn("ExtensionListing.aspx", "Called CreateTable()")
' create a datatable
Dim tblProps As New DataTable("props")
With tblProps
.Columns.Add("PropertyName", System.Type.GetType("System.String"))
.Columns.Add("PropertyValue",
System.Type.GetType("System.String"))
End With
ds.Tables.Add(tblProps)
End Function

Private Sub dgUsers_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles dgUsers.SelectedIndexChanged
Dim de As New
DirectoryEntry(ConfigurationSettings.AppSettings(" ActiveDirectoryPath"),
CustomAppSettings.GetAppSetting("ADUsername"),
CustomAppSettings.GetAppSetting("ADPassword"))
Dim src As New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=user)(Name=" & _
dgUsers.SelectedItem.Cells(1).Text & "))")
With src
.SearchRoot = de
.SearchScope = SearchScope.Subtree
End With
CreatePropsTable()
Dim res As SearchResult
Dim strUsername() As String
For Each res In src.FindAll
Dim ien As IDictionaryEnumerator = res.Properties.GetEnumerator
While ien.MoveNext
Dim strKey As String = CType(ien.Key, String)
If strKey = "department" Or strKey = "mail" Or strKey =
"telephonenumber" Then
If strKey = "telephonenumber" Then strKey = "Ext"
If strKey = "mail" Then strKey = "E-Mail"
If strKey = "department" Then strKey = "Department"
Dim dtr As DataRow = ds.Tables("props").NewRow
dtr("PropertyName") = strKey
If strKey = "E-Mail" Then
dtr("PropertyValue") = "<a href=""mailto:" &
res.Properties(CType(ien.Key, String))(0) & """>" &
res.Properties(CType(ien.Key, String))(0) & "</a>"
Else
dtr("PropertyValue") = res.Properties(CType(ien.Key,
String))(0)
End If
ds.Tables("props").Rows.Add(dtr)
End If
If strKey = "name" Then strUsername =
Split(res.Properties(CType(ien.Key, String))(0), ", ")
End While
Next
With lblUserName
.Text = strUsername(1) & " " & strUsername(0)
.Visible = True
End With
With dgProps
.DataSource = ds.Tables("props")
.DataBind()
End With
End Sub

Private Sub dgUsers_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
dgUsers.PageIndexChanged
With lblUserName
.Text = ""
.Visible = False
End With
With dgProps
.DataSource = Nothing
.DataBind()
End With
With dgUsers
.CurrentPageIndex = e.NewPageIndex
.SelectedIndex = -1
End With
LoadUserTable()
End Sub

"Torben Jensen" wrote:
Hi,

Does anyone have experience in retrieveing useraccount information like eg.
name, lastname, phonenumber, adress etc from Active Directory from an
asp.net application?

Perhaps standard components have already been developped to accomplish this
task?

Should I query the AD directly each time a request is made or should I
concider to replicate the AD information into a MS SQL database on a per day
basis to achieve the best performance possible and query the MS SQL database
instead?

Any help/links anything, would be appreciated.
Thank you

Kind regards
Torben

Nov 19 '05 #2
Hi Torben,

There's an article with code here on querying the schema:

http://www.codeproject.com/aspnet/adsi1.asp

And some code on this French-language site to retrieve the values:

http://www.aspfr.com/code.aspx?ID=8999

"Torben Jensen" <no@spam.dk> wrote in message
news:u5**************@TK2MSFTNGP09.phx.gbl...
Hi,

Does anyone have experience in retrieveing useraccount information like
eg.
name, lastname, phonenumber, adress etc from Active Directory from an
asp.net application?

Perhaps standard components have already been developped to accomplish
this
task?

Should I query the AD directly each time a request is made or should I
concider to replicate the AD information into a MS SQL database on a per
day
basis to achieve the best performance possible and query the MS SQL
database
instead?

Any help/links anything, would be appreciated.
Thank you

Kind regards
Torben


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dimitris Katsikas | last post by:
Hi everybody, I am trying to find a way to export automatically an entire database schema into an .xsd A graphical way is to drag & drop the tables from Server Connection into an empty .xsd...
5
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
1
by: onceuponapriori | last post by:
Greetings gents. I'm a Railser working on a django app that needs to do some scraping to gather its data. I need to programatically access a site that requires a username and password. Once I...
1
by: bubblegum | last post by:
I am working on a script that will retrieve process info from a Linux, a Windows, a Suse and a Solaris hosts. I run this script from a RedHat 2.6 machine. The first problem I have is how to get...
5
by: Johnny BeGood | last post by:
Hi All, Has anyone got any ideas on how to retrieve mobile phone info from a phone that connects to my web site, I want to use that data as part of logon authentication, for example: <?php...
3
by: David | last post by:
Hi, I have some code in my form as follows, to display 1 to 20 additional sets of fields to enter guest information. I am not sure how to retrieve these guests info so that I can post the info...
2
by: =?Utf-8?B?Q2FybG9zIFNvc2EgQWxiZXJ0?= | last post by:
Hi guys, Using C# I have a class with a number of public properties and a public method. The idea is to call the method (externally), selecting one of those properties. Do some work with the...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
6
by: cepera | last post by:
Hi guys! How I can retrieve "option value" info from select tag? I am using this code, but it is only let me get "name". I need to pass this value to second select tag. I found this code here:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.