Pages

Windows Identy / Windows Principal

identity3 MPj03415220000[1]

User identity is a common means of controlling access to a business application or limiting the options available within that application. The .NET Framework classes under the namespace System.Security.Principal are provided to assist in making such role-based security determinations.

*firstly you must add this dll :
System.Security.Principal;   System.Security.Policy;
then:
The Framework provides a WindowsIdentity class that represents an authenticated Windows user and a WindowsPrincipal class that encapsulates the WindowsIdentity and information about the user's role memberships. These objects representing the current user are accessible in one of two ways: using a static property on the Thread object or a static method on the WindowsIdentity object.
you can see example of windows identity and windows principal ;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        { 
            WindowsIdentity kimlik = WindowsIdentity.GetCurrent();
            Console.WriteLine(kimlik.Name.ToString());
            Console.WriteLine(kimlik.Token.ToString());
            Console.WriteLine(kimlik.AuthenticationType.ToString());

            if (kimlik.IsAnonymous)
                Console.WriteLine("Genel kullanıcı");
            if (kimlik.IsGuest)
                Console.WriteLine("Misafir kullancı");

            kimlik = WindowsIdentity.GetCurrent();
            WindowsPrincipal kimlik2 = new WindowsPrincipal(kimlik);
            Console.WriteLine(WindowsBuiltInRole.Administrator);
            kimlik2.IsInRole(WindowsBuiltInRole.Administrator);
            Console.ReadLine();

        }
    }
}

you will see like this when you run your code ….image