Last post Apr 12, 2015 05:21 AM by smirnov
Apr 10, 2015 12:27 PM|godistop1|LINK
I am not sure if this is the right forum.
Have APS.NET application. Need to find out if the current user is in one of two groups. Try several methods from the web, they will work in VS 2010, but not when I up loaded the application to the web server. The following is the latest code, get error
message when call the application is "Error Code 91 - Object reference not set to an instance of an object" when the line of code
Dim groups = user.GetGroups().
Public Sub InGroup()
btnChangeExamStatus.Enabled = False
btnChangeExamStatus.Visible = False
Dim userName = WindowsIdentity.GetCurrent.User.ToString()
Dim DC = New PrincipalContext(ContextType.Domain)
' find a user in the domain
Dim user = UserPrincipal.FindByIdentity(DC, userName)
Dim groups = user.GetGroups()
Dim groupNames = From g In groups Select g.DistinguishedName
For i As Integer = 0 To groups.Count - 1
If (groups(i).ToString() = "Transcription Intranet Access" OrElse groups(i).ToString() = "IT") Then
btnChangeExamStatus.Enabled = True
btnChangeExamStatus.Visible = True
Apr 12, 2015 05:21 AM|smirnov|LINK
There is a dedicated forum for AD and LDAP where you could find many similar threads, ex. http://forums.asp.net/t/1971340.aspx?Check+if+User+is+part+of+AD+Group
Under what identity is your process running on the server? Most likely, that user does not have the correct rights to access your Active Directory.
The membership in the Windows Authorization Access Group is required to execute GetAuthorizationGroups.
See the following article: http://support.microsoft.com/kb/331951
Also you can try
PrincipalSearchResult<Principal> groups = up.GetGroups();
Hope this helps.