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

P

Paul East

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
 
B

Beginner

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 said:
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))
 
P

Paul East

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.
 
B

Beginner

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top