Help on PrincipalPermission Demand Throwing Exception

Discussion in 'MCTS' started by Abba Biya, Feb 7, 2007.

  1. Abba Biya

    Abba Biya Guest

    [PrincipalPermission(SecurityAction.Demand, [email protected]"MYDomain\MyUserName")]
    static void TestMethod()
    Console.WriteLine("Test Message");

    public static void Main(string[] args)
    WindowsIdentity wID = WindowsIdentity.GetCurrent();
    Console.WriteLine("Current User: {0}", wID .Name);

    catch (System.Security.SecurityException ex)
    Console.WriteLine("Exception: {0}", ex.Message);

    Abba Biya, Feb 7, 2007
    1. Advertisements

  2. Abba Biya

    Abba Biya Guest

    Shoud add the following line for it to work.


    some observations:

    Security Principals listed on separate demands will be OR whereas if listed
    all in one SecurityAction.Demand, it will be AND.

    [PrincipalPermission(SecurityActioin.Demand, Authenticated = true, Role =
    will allow only authenticated and users from Admins group.

    If we change it to the following:
    [PrincipalPermission(SecurityActioin.Demand, Authenticated = true)]
    [PrincipalPermission(SecurityAction.Demand, Role = @"CONTOSO\Admins")]

    Authenticated users with out being Admins will be able to run this code.
    this is a Logical OR.

    This is great.
    Abba Biya, Feb 7, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.