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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.DirectoryServices Intermittently WOrking ?!

Status
Not open for further replies.

RhythmAddict112

Programmer
Joined
Jun 17, 2004
Messages
625
Location
US
Hi all...I have some code that I obtained from a FAQ here on tek-tips. (Thank you GloWorm27)

The code in and of itself works without issue. I'm grabbing a number of fields from A/D. The thing I just can't solve is why on earth this is working intermittently. I have the code sittin on my dev server, and no one is modifying it, myself included. Simlpy put, sometimes it works, sometimes it just doesnt. When it does not work, I get nothing - a completley blank screen. And when it does work, it displays all the fields I need to bring back (standard exchange fields as well as custom fields..) I just don't get it!!! Can anyone shed some light on this? My code is below for reference...

Code:
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.DirectoryServices

Public Class adsi
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblUserName As System.Web.UI.WebControls.Label
    Protected WithEvents Table1 As System.Web.UI.WebControls.Table
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents msg As System.Web.UI.WebControls.Label
    Protected WithEvents msg2 As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        SetupSession()
    End Sub

    Sub SetupSession()
        Dim strUserName As String
        Dim strRealName As String
        Dim strMisc As String
        Dim strADPath As String


        strUserName = HttpContext.Current.User.Identity.Name

        strADPath = "ourDomain.com"


        Dim Entry As DirectoryEntry = New DirectoryEntry("LDAP://" & strADPath, "", "")
        Dim Searcher As DirectorySearcher = New DirectorySearcher(Entry)


        Dim result As System.DirectoryServices.SearchResult

        Try


            Searcher.Filter = ("(sAMAccountName=" & strUserName & ")")

            result = Searcher.FindOne()

            strRealName = result.Properties("givenName")(0).ToString() & " " & result.Properties("sn")(0).ToString() & "<BR> " & result.Properties("streetAddress")(0).ToString() & "<BR>" & result.Properties("l")(0).ToString() & ", " & result.Properties("st")(0).ToString() & " " & result.Properties("postalCode")(0).ToString() & "<BR>" & result.Properties("telephoneNumber")(0).ToString() & "<BR>" & result.Properties("mail")(0).ToString() & "<BR>" & result.Properties("extensionattribute1")(0).ToString() & "<BR>" & result.Properties("extensionattribute12")(0).ToString() & "<BR>" & result.Properties("sAMAccountName")(0).ToString()

            msg.Text = strRealName
            'msg2.Text = strUserName

        Catch ex As Exception
            Dim debug As String = ex.Message
        End Try
    End Sub


End Class

Use your resources, you're on the internet!
 
I take that back, catching the exception I get this error...

Handling of this ADSVALUE type is not yet implemented (type = 0xb).

somethin to do with perms I think..Googling this; will post a solution just in case this comes in handy for someone else.. Would love any ideas though :)

Use your resources, you're on the internet!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top