Wednesday, October 18, 2006

Current user is a member of a specific windows
group


Authenticated applications normally need this type of functionality, what we need to do to implement this functionality is ..

1. Obtain a System.Security.Principal.WindowsIdentity object of the current user via the WindowsIdentity.GetCurrent.

2. Then create a System.Security.Principal.WindowsPrincipal class using the WindowsIdentity class

3. Then call the method IsInRole of the WindowsPrincipal object..


Sample code:

using System.Security.Principal;

WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);

//args is an arraylist of roles to include in the search
string[] args = {'domain\role1','domain\role2'}
foreach(string role in args){
--principal.IsInRole(role);
}

No comments: