473,847 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using ASP.Net to Get User Information from AD

Hey list, got this code running in a webform:

Dim DSESearcher As System.Director yServices.Direc torySearcher = New
System.Director yServices.Direc torySearcher
Dim RootDSE As String = DSESearcher.Sea rchRoot.Path
RootDSE = RootDSE.Insert( 7, "ou=users,ou=my users,")
Dim myDE As DirectoryEntry = New DirectoryEntry( RootDSE)
Dim myEntries As DirectoryEntrie s = myDE.Children
Dim thisentry As DirectoryEntry
thisentry = myEntries.Find( "cn=" & lastname)
Label1.Text = thisentry.Name

Obviously, this won't work because it's running as the ASP.Net user. How do
I go about getting another or hardcoded user to authenticate with
DSESearcher?

Thanks!
Derek
Nov 21 '05 #1
1 5031
See
http://support.microsoft.com/default...b;en-us;329986

Imports System
Imports System.Diagnost ics
Imports System.Director yServices
Imports System.Xml

Namespace ASPNet_App
'/ <summary>
'/
'/ </summary>
Public Class ADSIUtil
Protected m_strErrors As String = ""
Protected m_strRoot As String = ""
Protected m_obDirEnTry As DirectoryEnTry
Public Sub New()

End Sub
Public ReadOnly Property Errors() As String
Get
Return m_strErrors
End Get
End Property
Public Property RootNode() As String
Get
Return m_strRoot
End Get
Set (ByVal Value As String)
m_strRoot = value
End Set
End Property
Public Function Initialize(ByVa l strRoot As String) As Boolean
If m_strRoot = Nothing Or m_strRoot.Lengt h = 0 Then
RootNode = strRoot
End If

Try
m_obDirEnTry = New DirectoryEnTry( strRoot)
'--*' foreach (String propName in
m_obDirEnTry.Pr operties.Proper tyNames)
' {
' foreach (Object value in m_obDirEnTry.Pr operties(propNa me))
' {
' Trace.WriteLine ("name=" + propName + " value=" + value)
' }
' }
' */
Catch ex As Exception
Trace.WriteLine (ex.Message)
Return False
End Try
Return True
End Function
Public Function GetUserSchema(B yVal strLogin As String) As XmlDocument
Dim userDataDoc As XmlDocument = Nothing
' Make sure that we have a root node specified.
If m_strRoot = Nothing Or m_strRoot.Lengt h = 0 Then
m_strErrors += "Root Node not initializes"
Return userDataDoc
End If

Dim results As SearchResultCol lection
Dim srch As DirectorySearch er = New DirectorySearch er(m_obDirEnTry )
srch.Filter = ("(cn=" + strLogin + ")")

Try
results = srch.FindAll()
Catch ex As NotSupportedExc eption
m_strErrors += ex.Message
Trace.WriteLine (ex.Message)
Return userDataDoc
Catch ex As Exception
m_strErrors += "\n"
m_strErrors += ex.Message
Trace.WriteLine (ex.Message)
Return Nothing
End Try

Try
Dim result As SearchResult
For Each result In results
Dim coll As ResultPropertyC ollection = result.Properti es
Dim user As ADSIUser = New ADSIUser()
If False = user.Initialize (coll) Then
m_strErrors += "\n"
m_strErrors += "Failed to initialize the ADSI object"
Trace.WriteLine ("Failed to initialize the ADSI object")
Return Nothing
End If

If user.NumPropert ies > 0 Then
userDataDoc = user.GetUserPro perties()
End If
Next
Catch ex As Exception
m_strErrors += "\n"
m_strErrors += ex.Message
Trace.WriteLine (ex.Message)
Return Nothing
End Try

Return userDataDoc
End Function

'/ <summary>
'/
'/ </summary>
'/ <param name="strUser"> </param>
'/ <returns></returns>
Private Function DumpSchema(ByVa l strUser As String) As Boolean
If m_strRoot.Lengt h = 0 Then
Return False
End If

Dim results As SearchResultCol lection
Dim srch As DirectorySearch er = Nothing
Try
'DirectoryEntry schemaEntry = m_obDirEntry.Sc hemaEntry;
'Trace.WriteLin e(schemaEntry.C hildren.ToStrin g());
srch = New DirectorySearch er(m_obDirEnTry )
srch.Filter = ("(cn=" + strUser + ")")
results = srch.FindAll()

Dim result As SearchResult
For Each result In results
Dim coll As ResultPropertyC ollection = result.Properti es
Dim nItems As Integer = coll.Count
Dim myKey As String
For Each myKey In coll.PropertyNa mes
Dim tab As String = " "
Trace.WriteLine (myKey + " = ")
Dim myCollection As Object
For Each myCollection In coll(myKey)
Trace.WriteLine (tab + myCollection)
Next
Next
Next

Catch ex As Exception
Trace.WriteLine (ex.Message)
End Try

Return True
End Function
End Class
End Namespace

"Derek Martin" <dm*****@DONTSP AMMEokstateDOT. edu> wrote in message
news:dm*****@DO NTSPAMMEokstate DOT.edu:
Hey list, got this code running in a webform:

Dim DSESearcher As System.Director yServices.Direc torySearcher = New
System.Director yServices.Direc torySearcher
Dim RootDSE As String = DSESearcher.Sea rchRoot.Path
RootDSE = RootDSE.Insert( 7, "ou=users,ou=my users,")
Dim myDE As DirectoryEntry = New DirectoryEntry( RootDSE)
Dim myEntries As DirectoryEntrie s = myDE.Children
Dim thisentry As DirectoryEntry
thisentry = myEntries.Find( "cn=" & lastname)
Label1.Text = thisentry.Name

Obviously, this won't work because it's running as the ASP.Net user. How
do
I go about getting another or hardcoded user to authenticate with
DSESearcher?

Thanks!
Derek


Nov 21 '05 #2

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

Similar topics

0
285
by: Joe | last post by:
All While I know how to get the MS networking user information, I am looking for how to get th Novell login information as well. I should be able to get this information as easily as the M information, however I can't fine this documented Can anyone point me in the right direction? developer.novell.com hasn't been much help Any help would be greatly appreciated
2
10043
by: DotNetJunkies User | last post by:
Does anyone know how to get the user information such as Name, Address, Email, Phone Number, etc from Windows Active Directory? The samples I have seen so far don’t get the User Address, Email, or Phone Number! Thanks. --- Posted using Wimdows.net NntpNews Component - Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
1
4808
by: Haffi | last post by:
hi, I have a proplem creating a new user and/or adding additional information for root user in MySQL Administrator 1.0.19. When I do I get this message: error while storing the user information. Never the less, when I close the Admin program and open it again, the changes I tryed to make are saved, (althoug the program asked me if I wanted to save changes and I said no)
0
1566
by: Federica | last post by:
Hi! I need some help retrieving user information in Active Directory. I have one webform with 2 textboxes 1 username and one for password. When the user load this page and insert his username and password (the same that he use for the login on the Windows Domain - is a requirement!) he click the button login. At this point I need to connect to Active Directory searching if this username and this password are valid for this domain and I...
4
1537
by: sck10 | last post by:
Hello, I built a web site on our companies intranet. Is there a way to get the user information (user name, machine name etc.) when a person views a web page? -- Thanks in advance, sck10
7
2094
by: msc | last post by:
Hi guys, How to get the user information like userid written in C language.
3
5316
by: BlueSky | last post by:
Hi, I have to retrieve user information from active directory in ASP.NET by passing Employee ID to it. Can any one give me some information on how I should do this? Thanks!
0
1387
by: mazdotnet | last post by:
Hi, I'm trying to get the 'User Information' by using the UserId and it doesn't work. This works, MembershipUser membershipUser = Membership.GetUser("username");
1
1827
by: jerrydigital | last post by:
Hello, I am having trouble getting unique user information on my account page. Currently, once the user logs in, it will only display "Welcome...(then the same name pops up no matter who logs in)". After the login.html page, the form redirects the user to the loggedin.asp page which verifies the users email and password are in the database. Here's the loggedin.asp code: loggedin.asp: <%@ Language=VBScript %> <% Option Explicit %>...
2
2479
by: Yene | last post by:
Am trying to use my user object to hold one value after the user has logged in my website. when loging in the user object id is set using user.setid("id"); Once this is done. I want to use user.getid(); in a differernt method to update user record. I cant get the user object to hold the same value between the two methods /* * To change this template, choose Tools | Templates * and open the template in the editor.
0
9892
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9734
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10991
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10718
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10347
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9490
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7888
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7061
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4129
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.