Help with Role Based Security.

Posted by Bill K on Stack Overflow See other posts from Stack Overflow or by Bill K
Published on 2010-06-13T03:30:50Z Indexed on 2010/06/13 3:32 UTC
Read the original article Hit count: 350

Filed under:
|
|

Hello, I'm trying to understand role based security and I have the following method:

    [PrincipalPermission(SecurityAction.Demand, Role = "Administrators")]
    static void Test()
    {
        //administratos only can call this code
    }

What I wanna do is that only users that are members of the Windows Administrators group can call this code, however, if I do the following, it works:

        GenericIdentity genericIdentity = new GenericIdentity("test", "test");
        GenericPrincipal genericPrincipal = new GenericPrincipal(genericIdentity, new string[] { "Administrators" });
        AppDomain.CurrentDomain.SetThreadPrincipal(genericPrincipal);

        Test();

So, how can I make it work only if the user is in the Administrators windows group?

thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET