|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
User's PrivilegesHi all,
I need to know the user privileges (does user have administrator privileges) .. Which c# api's should i use? Thanks a lot March 31, 2005
Assuming you are developing a Windows application, you can examine the roles a user is in by using the System.Security.WindowsPrincipal class. (You can also do this in a web application but it requires windows authentication and impersonation.) This class provides the IsInRole method which accepts a string or WindowsBuiltInRole as an argument and returns a boolean value whether the user is in the requested role. It is used in this way: 'You have to obtain the WindowPrincipal object dim Prin as WindowsPrincipal = Threading.Thread.CurrentPrincipal if Prin.IsInRole(WindowsBuiltInRole.Administrator) = true then ' Perform tasks that should only be done if the user is an Admin else ' Perform limited or no tasks end if You can find more about this class on MSDN. Hope this helps and have a great day! Joseph MCAD Show quoteHide quote "Feldman Alex" wrote: > Hi all, > > > > I need to know the user privileges (does user have administrator privileges) > .. > > Which c# api's should i use? > > Thanks a lot > > > March 31, 2005
The namespace the WindowsPrincipal class is in is System.Security.Principal. I made a mistake in my last post. Best of luck! Joseph MCAD Show quoteHide quote "Joseph MCAD" wrote: > > March 31, 2005 > > Assuming you are developing a Windows application, you can examine the > roles a user is in by using the System.Security.WindowsPrincipal class. (You > can also do this in a web application but it requires windows authentication > and impersonation.) This class provides the IsInRole method which accepts a > string or WindowsBuiltInRole as an argument and returns a boolean value > whether the user is in the requested role. It is used in this way: > > 'You have to obtain the WindowPrincipal object > > dim Prin as WindowsPrincipal = Threading.Thread.CurrentPrincipal > if Prin.IsInRole(WindowsBuiltInRole.Administrator) = true then > > ' Perform tasks that should only be done if the user is an Admin > > else > > ' Perform limited or no tasks > > end if > > You can find more about this class on MSDN. Hope this helps and have a > great day! > > > Joseph MCAD > > > > "Feldman Alex" wrote: > > > Hi all, > > > > > > > > I need to know the user privileges (does user have administrator privileges) > > .. > > > > Which c# api's should i use? > > > > Thanks a lot > > > > > > March 31, 2005
Sorry, but before you can request certain roles, you first must assign the currently logon on user (according to the Windows OS for windows applications) to the threading.thread.currentprincipal by using this line of code before all others: appdomain.currentdomain.setprincipalpolicy(principalpolicy.windowsprincipal) If you want to use role demands everywhere in code, then you might want to put this line in the class's contructor or the form load event. Sorry, but it will work now. Joseph MCAD Show quoteHide quote "Joseph MCAD" wrote: > > March 31, 2005 > > Assuming you are developing a Windows application, you can examine the > roles a user is in by using the System.Security.WindowsPrincipal class. (You > can also do this in a web application but it requires windows authentication > and impersonation.) This class provides the IsInRole method which accepts a > string or WindowsBuiltInRole as an argument and returns a boolean value > whether the user is in the requested role. It is used in this way: > > 'You have to obtain the WindowPrincipal object > > dim Prin as WindowsPrincipal = Threading.Thread.CurrentPrincipal > if Prin.IsInRole(WindowsBuiltInRole.Administrator) = true then > > ' Perform tasks that should only be done if the user is an Admin > > else > > ' Perform limited or no tasks > > end if > > You can find more about this class on MSDN. Hope this helps and have a > great day! > > > Joseph MCAD > > > > "Feldman Alex" wrote: > > > Hi all, > > > > > > > > I need to know the user privileges (does user have administrator privileges) > > .. > > > > Which c# api's should i use? > > > > Thanks a lot > > > > > >
ClientCertificates and IIS5 with https://localhost
X.509 certificates and httpwebrequest Problem with RSACryptoServiceProvider ( incorrect usage of public-private keys ? ) Changing folder security RE: Designtime licenses, I just don't get it Custom principles and DnsPermission.Demand() revoke Windows authentication credentials for a session Sharing Application and Session scope with ASP in IIS6 HELP Security in .Net framework Decoding extended ascii base64 string |
|||||||||||||||||||||||