Hi All,
Please help. How to retrieve groups from username by using asp.net ?
My ldap server is domino ldap server. Thank you very much.
Hi All,
Please help. How to retrieve groups from username by using asp.net ?
My ldap server is domino ldap server. Thank you very much.
For that you need to put the following code, whenever you log from username by using asp.net. If you need to when the page first loads, the you can do this in the Page_Load or Page_Init Events
Hope so it may help you out.Sub Page_Load( Object as sender, EventArgs as e )
Dim username as String = Page.User.Identity.Name
'do something with username
End Sub
Hi Modifier,
Thanks for your help first.
I mean that finding domino groups of logged in user.
e.g.
Searched by kelvin
Group List
-----------
IT Department
I found simlar source code, but it doesn't work.
StringCollection groups = new StringCollection();
DirectorySearcher srch = new DirectorySearcher(RootDirectoryEntry,"(sAMAccountName=" + strUser + ")");
// set properties to retrieve
srch.PropertiesToLoad.Add("memberOf");
srch.PropertiesToLoad.Add("sAMAccountName");
// find one entry since there should be no duplicates of sam account name
// in the active directory
SearchResult res = srch.FindOne();
// clear the groups collection for safe measure
groups.Clear();
// get the number of groups that the user is a member of
int propertyCount = res.Properties["memberOf"].Count;
// create some variables for the looping through groups
String dn;
int equalsIndex, commaIndex;
// loop through groups
for( int propertyCounter = 0; propertyCounter < propertyCount; propertyCounter++)
{
dn = (String)res.Properties["memberOf"][propertyCounter];
// the following is used to remove the cn= etc...
equalsIndex = dn.IndexOf("=", 1);
commaIndex = dn.IndexOf(",", 1);
if (-1 == equalsIndex)
{
}
else
{
// add string to group collection
groups.Add(dn.Substring((equalsIndex + 1),(commaIndex - equalsIndex) - 1));
}
}
Hi All,
Here is attached my source code, I try to pass administrator or user account, but the error message shown "Accessed Denied".
ldappath = "LDAP://192.168.1.10"
Dim MyDirectory As DirectoryEntry
MyDirectory = New DirectoryEntry(ldappath, txtUsername, txtPassword, AuthenticationTypes.None)
Dim groups As StringCollection = New StringCollection()
Dim srch As DirectorySearcher = New DirectorySearcher(MyDirectory, "(&(givenName=" + txtUsername + "))")
srch.PropertiesToLoad.Add("memberOf")
srch.PropertiesToLoad.Add("givenName")
srch.SearchScope = SearchScope.Subtree
Dim res As SearchResult = srch.FindOne()
groups.Clear()
Dim propertyCount As Integer = res.Properties("memberOf").Count
Dim dn As String
Dim equalsIndex, commaIndex As Integer
For propertyCounter As Integer = 0 To propertyCounter < propertyCount
dn = res.Properties("memberOf")(propertyCounter).ToString
equalsIndex = dn.IndexOf("=", 1)
commaIndex = dn.IndexOf(",", 1)
If (-1 = equalsIndex) Then
Else
groups.Add(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1))
End If
Next
Hi,
I have similar problem & I used WindowsTokenRoleProvider & I could find out my username & got all the Groups I belong on my system. CAn I do the same but against active directory? Do I need to use "AuthorizationStoreRoleProvider"? & install azman?
Bookmarks