Problems when authenticating against the Active Directory using Forms Authentication and Visual Basic .NET

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Problems when authenticating against the Active Directory using Forms Authentication and Visual Basic .NET

    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 ([url]http://support.microsoft.com/default.aspx?scid=kb;EN-US;326340[/url])

    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")(propertyCounte r), 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 Guest

  2. Similar Questions and Discussions

    1. Asp.Net Forms authentication using Active Directory
      Hi. I am using forms authentication in ASP.Net against Active Directory. I have followed the example provided by Microsoft. Here is my problem....
    2. Role based Forms Authentication (using Active Directory)
      Hi All, Can anybody here kindly forward me a sample of a Role based forms Authentication using Acitve Directory? Thanks alot. P
    3. Forms Authentication with Active Directory using vb.net
      I have seen many examples of form authentication using c#. Can someone point me to a sample using vb.net. I would like to use WinNT://domain,...
    4. Forms or windows authentication with active directory?
      Hi, I'm having a hard time deciding (figuring out) how to implement security in my asp.net application. Requirements: - Use active directory as...
    5. Active Directory, LDAP and Forms Authentication Problem
      Hi, I've got an intranet ASP.NET application that uses Forms Authentication. What I'd like to do is get the username (in the format name.surname)...
  3. #2

    Default Re: Problems when authenticating against the Active Directory using Forms Authentication and Visual Basic .NET

    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" <paul.east@gmacrfc.co.uk> wrote in message
    news:23DDF00C-8D75-42F9-BC92-0232E13A5C3B@microsoft.com...
    > 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
    ([url]http://support.microsoft.com/default.aspx?scid=kb;EN-US;326340[/url]).
    >
    > 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")(propertyCounte r), 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 Guest

  4. #3

    Default Re: Problems when authenticating against the Active Directory using Forms Authentication and Visual Basic .NET

    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 Guest

  5. #4

    Default Re: Problems when authenticating against the Active Directory using Forms Authentication and Visual Basic .NET

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

    "Paul East" <paul.east@GMACRFC.co.uk> wrote in message
    news:540950F3-C861-46CE-BFDD-C476457AA72C@microsoft.com...
    > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139