This documentation is archived and is not being maintained.

GenericIdentity Class

Represents a generic user.

Namespace:  System.Security.Principal
Assembly:  mscorlib (in mscorlib.dll)

public class GenericIdentity : IIdentity

An identity object represents the user on whose behalf the code is running.

The following example shows the use of members of the GenericIdentity class.

using System;
using System.Security.Principal;

class GenericIdentityMembers
    static void Main(string[] args)
        // Create a GenericIdentity object with no authentication type  
        // specified.
        GenericIdentity defaultIdentity = new GenericIdentity("DefaultUser");

        // Retrieve a GenericIdentity created from current WindowsIdentity 
        // values.
        GenericIdentity currentIdentity = GetGenericIdentity();

        ShowIdentityPreferences(new GenericIdentity(""));

        Console.WriteLine("The sample completed successfully; " +
            "press Enter to continue.");

    // Print identity preferences to the console window. 
    private static void ShowIdentityPreferences(
        GenericIdentity genericIdentity)
        // Retrieve the name of the generic identity object.
        string identityName = genericIdentity.Name;

        // Retrieve the authentication type of the generic identity object.
        string identityAuthenticationType = 

        Console.WriteLine("Name: " + identityName);
        Console.WriteLine("Type: " + identityAuthenticationType);

        // Verify that the user's identity has been authenticated 
        // (was created with a valid name). 
        if (genericIdentity.IsAuthenticated)
            Console.WriteLine("The user's identity has been authenticated.");
            Console.WriteLine("The user's identity has not been " + 

    // Create generic identity based on values from the current 
    // WindowsIdentity. 
    private static GenericIdentity GetGenericIdentity()
        // Get values from the current WindowsIdentity.
        WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();

        // Construct a GenericIdentity object based on the current Windows 
        // identity name and authentication type.
        string authenticationType = windowsIdentity.AuthenticationType;
        string userName = windowsIdentity.Name;
        GenericIdentity authenticatedGenericIdentity =
            new GenericIdentity(userName, authenticationType);

        return authenticatedGenericIdentity;


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0