Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Component Works Standalone, Not In asp.net Page

Status
Not open for further replies.

goldenboynh

Programmer
May 22, 2003
2
US
Hi -

I have code that returns exchange information for a particular user from our exchange server. I initially had this running in a vb.net program, and could verify the functionality works correctly (I printed the results to a text file).

I then transitioned the vb file to a class in order to use it from within an asp.net page. I have a function that accesses the exchange server based upon the uid filter. It then sets approximately 20 properties based upon values from the exchange server for a particular user.

The object compiled without error. I then created a very lightweight asp.net page to test the component. However, the component doesn't appear to be working. It's return false, when running in the vb file (see above) it returns true. Any ideas? I have included the code below:

'############### vb.net component #############
Imports System
Imports System.DirectoryServices
Imports System.Collections

Namespace WebUtilities

Public Class EmployeeInfo

Private mstrRDN As String
'... a lot more string declared here...
Private mstrFileId As String

Public Function GetEmployeeInfo(ByVal strUsername As String) As Boolean
Dim objEntry As DirectoryEntry
Dim objSearcher As DirectorySearcher
Dim objSearchResult As SearchResult
Dim objDisplayName As Object
Dim strDisplayName As String

Try

objEntry = New DirectoryEntry("LDAP://exchange-server/ou=CORP,o=mycompany")

' Set up to search for UserMan on the Users node
objSearcher = New DirectorySearcher(objEntry)
objSearcher.Filter = "(&(uid=" & strUsername & "))"

' Find the user
objSearchResult = objSearcher.FindOne()

' Check if the user was found
If Not objSearchResult Is Nothing Then
' Display path for user

Dim myResultPropColl As ResultPropertyCollection
Dim theValue As String
myResultPropColl = objSearchResult.Properties
Dim myKey As String
Dim colHashTable As Hashtable
colHashTable = New Hashtable()


For Each myKey In myResultPropColl.PropertyNames
Dim tab1 As String = " "
Dim myCollection As Object
For Each myCollection In myResultPropColl(myKey)
If myCollection.GetType().ToString() = "System.String" Then
colHashTable(myKey) = myCollection.ToString()
End If
Next myCollection
Next myKey

mstrRDN = colHashTable("rdn")
'... a lot more properties set here...
mstrFileId = colHashTable("extension-attribute-1")

Return True
Else
Return False
End If
Catch

End Try
End Function

Property RDN() As String
Get
Return mstrRDN
End Get
Set(ByVal Value As String)
mstrRDN = Value
End Set
End Property

'... a lot more property declarations here...

Property FileID() As String
Get
Return mstrFileId
End Get
Set(ByVal Value As String)
mstrFileId = Value
End Set
End Property
End Class

End Namespace


'############### asp.net file #############
Imports System.DirectoryServices
Imports WebUtilities.EmployeeInfo

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents lblOut As System.Web.UI.WebControls.Label

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim myEmployee As WebUtilities.EmployeeInfo
Dim bolRtn As Boolean

myEmployee = New WebUtilities.EmployeeInfo()
bolRtn = myEmployee.GetEmployeeInfo("jdoe")

lblOut.Text = "File ID: " & myEmployee.Department & ", " & bolRtn

End Sub

End Class
 
I have figured out what is happening, but can't resolve the problem. For some reason, from vb, I don't need to validate with a username and password against the exchange server. However, when I have to do this from the asp.net page, which then only allows me to access information for the specific account associated with the username/password pair.

Thus if I am logging in as John Doe, and want to view exchange info for a different username, the application errors out.

So from vb, I can access exchange through:

Code:
DirectoryEntryobjEntry = New DirectoryEntry("LDAP://exchange-server/ou=CORP,o=mycompany")

and return information for any username. However, when compiled and called from asp.net, it doesn't work unless a username/password is passed, and then it only returns information for that specific username/password.

Is there a setting in IIS that I need to turn off? Something similar?

Any help would be greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top