I am using C# to get the Role from Azman Manager by login User.
This is my code,
internal string AzRoleCheck(string strUserName)
{
string strRoleName = string.Empty;
try
{
WindowsIdentity userIdentity = new WindowsIdentity(strUserName);
clientContext = azApplication.InitializeClientContextFromToken((ulong)userIdentity.Token, null);
foreach (IAzRole Azrole in azApplication.Roles)
{
strRoleName = Azrole.Name;
foreach (object member in (object[])Azrole.MembersName)
{
string strMemberName = member.ToString();
string[] str1 = Regex.Split(strMemberName, "@");
if (string.Equals(str1[0],strUserName,StringComparison.CurrentCultureIgnoreCase))
return strRoleName;
}
}
}
catch (Exception)
{
throw;
}
return strRoleName;
}
When the ad-user login to my application, call this above method with 'strUserName' parameter. Here, i am checking the all user roles from azman by using foreach & within this foreach getting membername
based on role & then checking all this members is available under the role or not. If the member is available under the role means return the userrole as string.
It's working fine, but my question is , Is it a correct method to get the role based on user???
I have a question, i added a AD-User group to Azman, Now i am logging in through userName, how do i get the Azman role ?
Thanks in advance...