Hi,
hmm, if it works in VB.Net it should also work in C#.
Have you tried IsInRole("DOMAINNAME\GROUPNAME")?
You can also try to see if the user is an administrator.
IsInRole(WindowsBuiltInRole.Administrator)
This should work.
Example:
WindowsIdentity myIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal myPrincipal = new WindowsPrincipal(myIdentity);
if( myPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
{
//This use is an Administrotor
}
/Fredrik Normén
>From: "Yu, Kevin" <kyu@N...>
>Reply-To: "ASPX_Professional" <aspx_professional@p...>
>To: "ASPX_Professional" <aspx_professional@p...>
>Subject: [aspx_professional] Re: windows authentication with c#?
>Date: Wed, 19 Dec 2001 09:47:15 -0500
>
>now how to identify a login user is an administrator of the system?
>
>it seems that IsRoleof() function doesn't work. I follow the example from
>MSDN, IsRoleof() always returns false. but I try the similar code in
>VB.net,
>it works fine and it can even identify different group other than those
>build in group. I guess C# has its weakness comparing to Vb at this point.
>
>
>
>-----Original Message-----
>From: Fredrik Normén [mailto:fnormen@h...]
>Sent: Wednesday, December 19, 2001 4:19 AM
>To: ASPX_Professional
>Subject: [aspx_professional] Re: windows authentication with c#?
>
>
>Hi,
>
>There are two ways of doing that.
>
>1. Repeatedly perfrom role-based validation.
>2. Make role-based validations once.
>
>If you need to repeatedly perform role-based validation you
>first call the SetPrincipalPolicy method on the System.AppDomain object,
>passing it a PrincipalPolicy enumeration value that indicates what the
>new policy should be. The one you should use is
>PrincipalPolicy.WindowsPrincipal, following code demonstrates this call.
>
>AppDomain.CurrentDomain.SetPrincipalPolicy
>(PrincipalPolicy.WindowsPrincipal);
>
>After this, you use the Thread.CurrentPrincipal property to retrieve the
>principal that encapsulates the current Windows user.
>The following code initializes a new WindowsPrincipal object to the value
>of the principal associated with the current thread.
>
>WindowsPrincipal myPrincipal = (WindowsPrincipal) Thread.CurrentPrincipal
>
>Now you have your principal object.
>
>If you only needs to make role-based validations once, you can do this.
>
>First of all you need to initialize a new instance of the WindowsIdentity
>class by calling the WindowsIdentity.GetCurrent method, which queries the
>current Windows account and places information about that account into
>the newly created identity object. The following code creates a new
>instance of the class and initializes it to the current authenticated
>user.
>
>WindowsIdentity MyIdentity = WindowsIdentity.GetCurrent();
>
>After this you have to create a new instance of the Principal class and
>pass it the value of a WindowsIdentity object. The following code
>demonstrates the creation of a new WindowsPrincipal object initialized
>with the previously created WindowsIdentity object.
>WindowsPrincipal MyPrincipal = new WindowsPrincipal(MyIdentity);
>
>When the principal object has been created, you can use one of several
>methods to validate it.
>
>Here is an exmaple of doing that.
>
>//Get the current identity and put it into an identity object.
>WindowsIdentity MyIdentity = WindowsIdentity.GetCurrent();
>
>//Put the previous identity into a principal object.
>WindowsPrincipal MyPrincipal = new WindowsPrincipal(MyIdentity);
>
>//Principal values.
>string Name = MyPrincipal.Identity.Name;
>string Auth = MyPrincipal.Identity.IsAuthenticated.ToString();
>
>Regards,
>Fredrik Normén
>
>
> > doesn't anyone have any working example of windows authentication using
>c#
> > to identify if a login user
> > MyPrincipal.IsInRole("Administrator")?
> >
> > thanks
> >
> >
>
>$subst('Email.Unsub').
>
>$subst('Email.Unsub').
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx