Re: IsInRole does not seem to work
From: Shel Blauman [MSFT] (sheldonb_at_online.microsoft.com)
Date: 09/16/03
- Next message: Shel Blauman [MSFT]: "Re: Still can't get isinrole to work and what about localization issues with the roles"
- Previous message: RDufour: "Still can't get isinrole to work and what about localization issues with the roles"
- In reply to: RDufour: "Re: IsInRole does not seem to work"
- Next in thread: Herbert Stejdir: "Re: IsInRole does not seem to work"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 16 Sep 2003 08:48:18 -0700
Use the string machinename\customRole.
Shel
-- This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm "RDufour" <rdufour@sgiims.com> wrote in message news:u226ud$eDHA.3248@tk2msftngp13.phx.gbl... > How do you check to see if it's not a built-in user group like > administrators or users, but other user groups created by the network > administrator, like Sales, Personnel etc.. > > Thanks for the help, > > Bob > > "Shel Blauman [MSFT]" <sheldonb@online.microsoft.com> wrote in message > news:%23FscUF8eDHA.3788@tk2msftngp13.phx.gbl... > > Try this code, it works for me: > > > > Imports System > > > > Imports System.Security.Principal > > > > Public Class TestIsInRole > > > > ' A simple sample to demonstrate how to test whether the current > > > > ' principal (user) is in a built-in role. > > > > Public Shared Sub Main() > > > > Dim id As WindowsIdentity > > > > id = WindowsIdentity.GetCurrent() > > > > Dim p As New WindowsPrincipal(id) > > > > Console.WriteLine("Am I an administrator? {0}", > > p.IsInRole("builtin\administrators").ToString()) > > > > Console.WriteLine("Am I an administrator? {0}", > > p.IsInRole(WindowsBuiltInRole.Administrator).ToString()) > > > > Console.WriteLine("Hit enter to exit") > > > > Console.ReadLine() > > > > End Sub 'Main > > > > End Class 'TestIsInRole > > > > > > > > Shel > > > > > > -- > > This posting is provided "AS IS" with no warranties, and confers no > rights. > > Use of included script samples are subject to the terms specified at > > http://www.microsoft.com/info/cpyright.htm > > > > > > "RDufour" <rdufour@sgiims.com> wrote in message > > news:OqpSLD8eDHA.2184@TK2MSFTNGP10.phx.gbl... > > > No, I had to write (in vb) > > > > > > AppDomain.CurrentDomain.SetPrincipalPolicy(Principal.PrincipalPolicy.Windows > > > Principal) > > > > > > But it does not work, I still always get false no matter what. > > > > > > > > > > > > Bob > > > > > > "Eugene V. Bobukh [MS]" <eugenebo@online.microsoft.com> wrote in message > > > news:ellEU57eDHA.1712@TK2MSFTNGP11.phx.gbl... > > > Does it help if you set up current PrincipalPolicy to WindowsPrincipal > > > before the first check? E.g., > > > > > > > > > > > > AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal) > > > ; > > > > > > > > > -- > > > > > > Eugene V. Bobukh > > > > > > This message is provided "AS IS" with no warranties, and confers no > > rights. > > > Any opinions or policies stated within it are my own and do not > > necessarily > > > constitute those of my employer. > > > > > > ---- > > > > > > "RDufour" <rdufour@sgiims.com> wrote in message > > > news:OvfGVJ7eDHA.2344@TK2MSFTNGP10.phx.gbl... > > > > The following code > > > > > > > > Dim myUser As System.Security.Principal.WindowsIdentity > > > > > > > > Dim winPrincipal As New > > > > > > > > > > System.Security.Principal.WindowsPrincipal(System.Security.Principal.Windows > > > > Identity.GetCurrent()) > > > > > > > > Dim username As String = winPrincipal.Identity.Name > > > > > > > > If winPrincipal.IsInRole("Users") Then > > > > > > > > 'OK > > > > > > > > Else > > > > > > > > 'Not OK > > > > > > > > End If > > > > > > > > Always returns NOT OK even though while debugging I can see my > username > > > > correctly I can go to the local administration on my server that I > > develop > > > > om (w2k- SP4) see that my username Bob is part of users administrators > > and > > > > part of Users. No matter what usergroup I write in (checking > > > capitalization > > > > is same) the isinRole function never returns True. > > > > > > > > Can anyone tell me what's wrong? > > > > > > > > > > > > > > > > Thanks in advance, > > > > > > > > > > > > > > > > Bob > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
- Next message: Shel Blauman [MSFT]: "Re: Still can't get isinrole to work and what about localization issues with the roles"
- Previous message: RDufour: "Still can't get isinrole to work and what about localization issues with the roles"
- In reply to: RDufour: "Re: IsInRole does not seem to work"
- Next in thread: Herbert Stejdir: "Re: IsInRole does not seem to work"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|