I have never worked on authorization in Vb.Net before. So the below question might sound stupid for advanced programmers. Please apologize.
I am trying to get the list of the Active Directory Groups of the logged in user. I was told that Roles.GetRolesForUser() is the best way to achieve it. I wrote the below code in my web.config.
<roleManager
enabled="true"
cacheRolesInCookie="true" >
</roleManager>
and added the below code in code behind.
Dim userRoles As String() = Roles.GetRolesForUser()
I see the userRoles.length is 0. I verified the user is having more than one active directory groups associated with. Either this is because the configuration which I set in web.config is wrong or this is not the way to get all the active directory groups for this user. Any suggestions are appreciated.
Either I am too stupid to understand the Roles.GetRolesForUser() or configuring it is really hard.:)
I solved this problem using
IsInRole()method. I knew the possible ADGroups which would access my app and made that as a configurable item in web.config. Then usedString.Split()and then manually checked withHttpContext.Current.User.IsInRole()to verify the user can access the app.