Checking for access in a role : Role « Security « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Security;
using System.Security.AccessControl;
using System.Security.Policy;
using System.Security.Permissions;
using System.Security.Principal;
using System.Text;

public class MainClass
{
    public static void Main()
    {
        IPrincipal user = Thread.CurrentPrincipal;
        if (!user.IsInRole("Administrators"))
            Console.WriteLine("User not in the 'admin' role");
        else
            Console.WriteLine("User is an 'admin'");
    }
}
User not in the 'admin' role








35.2.Role
35.2.1.Checking for access in a role
35.2.2.Declarative role-based security