obrienkev

Hi,

I have created a usergroup called 'SetAdministrators'.

isAdmin should be set to true as my login details are part of the usergroup.

But isAdmin is displayed as 'false'.

Why is this What am I missing The commented out line is displayed as 'true' when in use.

Code Snippet

WindowsIdentity wi = WindowsIdentity.GetCurrent();

WindowsPrincipal wp = new WindowsPrincipal(wi);

bool isAdmin = wp.IsInRole("Project\\" + "SetAdministrators");

//bool isAdmin = wp.IsInRole("BUILTIN\\" + "Administrators");

MessageBox.Show(isAdmin.ToString());

Thanks.



Re: Visual C# General User Roles

TaylorMichaelL

I'm taking a guess here but did you log out and back in after modifying the group membership. Group membership is cached at logon . Therefore any changes to group membership will not be seen until you log out and back in.

Michael Taylor - 6/5/07

http://p3net.mvps.org





Re: Visual C# General User Roles

obrienkev

Did that but no change.

Are these getting me the Windows Login Roles or the SQL Server Roles

I want the Windows ones

Thanks.





Re: Visual C# General User Roles

TaylorMichaelL

It will get you the roles associated with the Windows user account. If you wanted to get the roles associated with a SQL Server login you'd have to go through SQL Server. For clarification the API only works with Windows users assigned to Windows groups through the MMC snapin for creating users and groups. It does not work with any server or application roles you might define or configure in SQL Server. Therefore if the group you're trying to retrieve is a SQL group or defined within SQL Server it won't work.

Given your example the machine name would be Project. Is this correct

Michael Taylor - 6/5/07

http://p3net.mvps.org





Re: Visual C# General User Roles

obrienkev

No Project is not the name of the machine.

Just the user group