Problems when authenticating against the Active Directory using Forms Authentication and Visual Basi

Discussion in 'ASP .Net Security' started by Paul East, Mar 1, 2004.

  1. Paul East

    Paul East Guest

    I have recently followed the document to allow authentication against Active Directory using Forms authentication as described in the the Microsoft Knowledge Base Article 326340 (http://support.microsoft.com/default.aspx?scid=kb;EN-US;326340)

    I can authenticate correctly, but when I attempt to retrieve the groups for the user I get the following error

    Object reference not set to an instance of an object

    I have changed the code slightly to pull back the properties I have access to for the user but memberOf is not listed

    Have I missed something, or is there some AD configuration needed to expose this

    The code I'm working with is below

    I hope someone can assist me with this

    Thanks in advance

    Paul Eas

    Public Function GetGroups() As Strin
    Dim search As DirectorySearcher = New DirectorySearcher(_path
    search.Filter = "(cn=" & _filterAttribute & ")
    search.PropertiesToLoad.Add("memberOf"

    Dim groupNames As StringBuilder = New StringBuilde

    Tr
    Dim result As SearchResult = search.FindOn

    '---------------> The error occours when the line below is uncommented
    'Dim propertyCount As Integer = result.Properties("memberOf").Coun

    'Dim dn As Strin
    'Dim equalsIndex, commaInde

    'Dim propertyCounter As Intege

    'For propertyCounter = 0 To propertyCount -
    'dn = CType(result.Properties("memberOf")(propertyCounter), String

    'equalsIndex = dn.IndexOf("=", 1
    'commaIndex = dn.IndexOf(",", 1
    'If (equalsIndex = -1) The
    'Return Nothin
    'End I

    'groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1)
    'groupNames.Append("|"
    'Nex

    Catch ex As Exceptio
    Throw New Exception("Error obtaining group names. " & ex.Message
    End Tr

    Return groupNames.ToString(
    End Function
    Paul East, Mar 1, 2004
    #1
    1. Advertising

  2. Paul East

    Beginner Guest

    Someone does not have MemberOf properties. You need to test If
    result.Contains("MemberOf"), or something like that. It's a pain if you
    have a long list, hope they change the behavior in the futuer to treat null
    as empty string.

    "Paul East" <> wrote in message
    news:...
    > I have recently followed the document to allow authentication against

    Active Directory using Forms authentication as described in the the
    Microsoft Knowledge Base Article 326340
    (http://support.microsoft.com/default.aspx?scid=kb;EN-US;326340).
    >
    > I can authenticate correctly, but when I attempt to retrieve the groups

    for the user I get the following error:
    >
    > Object reference not set to an instance of an object.
    >
    > I have changed the code slightly to pull back the properties I have access

    to for the user but memberOf is not listed.
    >
    > Have I missed something, or is there some AD configuration needed to

    expose this?
    >
    > The code I'm working with is below.
    >
    > I hope someone can assist me with this,
    >
    > Thanks in advance,
    >
    > Paul East
    >
    > Public Function GetGroups() As String
    > Dim search As DirectorySearcher = New DirectorySearcher(_path)
    > search.Filter = "(cn=" & _filterAttribute & ")"
    > search.PropertiesToLoad.Add("memberOf")
    >
    > Dim groupNames As StringBuilder = New StringBuilder
    >
    > Try
    > Dim result As SearchResult = search.FindOne
    >
    > '---------------> The error occours when the line below is uncommented:
    > 'Dim propertyCount As Integer =

    result.Properties("memberOf").Count
    >
    > 'Dim dn As String
    > 'Dim equalsIndex, commaIndex
    >
    > 'Dim propertyCounter As Integer
    >
    > 'For propertyCounter = 0 To propertyCount - 1
    > 'dn =

    CType(result.Properties("memberOf")(propertyCounter), String)
    >
    > 'equalsIndex = dn.IndexOf("=", 1)
    > 'commaIndex = dn.IndexOf(",", 1)
    > 'If (equalsIndex = -1) Then
    > 'Return Nothing
    > 'End If
    >
    > 'groupNames.Append(dn.Substring((equalsIndex + 1),

    (commaIndex - equalsIndex) - 1))
    > 'groupNames.Append("|")
    > 'Next
    >
    > Catch ex As Exception
    > Throw New Exception("Error obtaining group names. " &

    ex.Message)
    > End Try
    >
    > Return groupNames.ToString()
    > End Function
    Beginner, Mar 1, 2004
    #2
    1. Advertising

  3. Paul East

    Paul East Guest

    Thanks Beginner

    The memberOf attribute is definately not in the list of exposed attributes from the code I posted

    Has anyone else tried this code against their AD

    Paul.
    Paul East, Mar 1, 2004
    #3
  4. Paul East

    Beginner Guest

    Didn't quite get what you are trying to say. You mean you didn't use
    memberOf?

    "Paul East" <> wrote in message
    news:...
    > Thanks Beginner,
    >
    > The memberOf attribute is definately not in the list of exposed attributes

    from the code I posted.
    >
    > Has anyone else tried this code against their AD?
    >
    > Paul.
    Beginner, Mar 2, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Lambert
    Replies:
    3
    Views:
    405
    Alan Lambert
    Feb 11, 2009
  2. Boesman
    Replies:
    1
    Views:
    227
    Joe Kaplan
    Jan 8, 2007
  3. Alan Lambert
    Replies:
    2
    Views:
    712
    Alan Lambert
    Feb 11, 2009
  4. Ruggiero, Vince
    Replies:
    0
    Views:
    729
    Ruggiero, Vince
    Dec 14, 2009
  5. Ruggiero, Vince
    Replies:
    0
    Views:
    868
    Ruggiero, Vince
    Dec 14, 2009
Loading...

Share This Page