Esta documentación está archivada y no tiene mantenimiento.

GenericIdentity (Clase)

Actualización: noviembre 2007

Representa a un usuario genérico.

Espacio de nombres:  System.Security.Principal
Ensamblado:  mscorlib (en mscorlib.dll)

[SerializableAttribute]
[ComVisibleAttribute(true)]
public class GenericIdentity : IIdentity
/** @attribute SerializableAttribute */ 
/** @attribute ComVisibleAttribute(true) */
public class GenericIdentity implements IIdentity
public class GenericIdentity implements IIdentity

Un objeto de identidad representa al usuario en cuyo nombre se ejecuta el código.

En el siguiente ejemplo se muestra el uso de miembros de la clase GenericIdentity.

using System;
using System.Security.Principal;

class GenericIdentityMembers
{
    [STAThread]
    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(""));
        ShowIdentityPreferences(defaultIdentity);
        ShowIdentityPreferences(currentIdentity);

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

    // 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 = 
            genericIdentity.AuthenticationType;

        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.");
        }
        else
        {
            Console.WriteLine("The user's identity has not been " + 
                "authenticated.");
        }
        Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~");
    }

    // 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;
    }
}




import System.*;
import System.Security.Principal.*;

class GenericIdentityMembers
{
    /** @attribute STAThread()
     */
    public 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(""));
        ShowIdentityPreferences(defaultIdentity);
        ShowIdentityPreferences(currentIdentity);

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

    // Print identity preferences to the console window.
    private static void ShowIdentityPreferences(GenericIdentity genericIdentity)
    {
        // Retrieve the name of the generic identity object.
        String identityName = genericIdentity.get_Name();
        // Retrieve the authentication type of the generic identity object.
        String identityAuthenticationType 
            = genericIdentity.get_AuthenticationType();
        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.get_IsAuthenticated()) {
            Console.WriteLine("The user's identity has been authenticated.");
        }
        else {
            Console.WriteLine("The user's identity has not been " 
                + "authenticated.");
        }
        Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~");
    } //ShowIdentityPreferences

    // 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.get_AuthenticationType();
        String userName = windowsIdentity.get_Name();
        GenericIdentity authenticatedGenericIdentity 
            = new GenericIdentity(userName, authenticationType);
        return authenticatedGenericIdentity;
    } //GetGenericIdentity
} //GenericIdentityMembers


System.Object
  System.Security.Principal.GenericIdentity
    System.Net.HttpListenerBasicIdentity

Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

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

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0, 2.0, 1.1, 1.0
Mostrar: