Exportar (0) Imprimir
Expandir todo

Thread.CurrentPrincipal (Propiedad)

Obtiene o establece el principal del subproceso actual (de la seguridad basada en funciones).

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

public static IPrincipal CurrentPrincipal { get; set; }
/** @property */
public static IPrincipal get_CurrentPrincipal ()

/** @property */
public static void set_CurrentPrincipal (IPrincipal value)

public static function get CurrentPrincipal () : IPrincipal

public static function set CurrentPrincipal (value : IPrincipal)

No aplicable.

Valor de propiedad

Valor de IPrincipal que representa el contexto de seguridad.

Tipo de excepciónCondición

SecurityException

El llamador no tiene el permiso requerido para establecer el principal.

En el ejemplo de código siguiente se muestra la forma de establecer y recuperar el principal de un subproceso.

using System;
using System.Security;
using System.Security.Permissions;
using System.Security.Principal;
using System.Threading;

// Request permission to set thread principal.
[assembly: SecurityPermissionAttribute(
    SecurityAction.RequestOptional, ControlPrincipal = true)]
class Principal
{
    static void Main()
    {
        string[] rolesArray = {"managers", "executives"};
        try
        {
            // Set the principal to a new generic principal.
            Thread.CurrentPrincipal = 
                new GenericPrincipal(new GenericIdentity(
                "Bob", "Passport"), rolesArray);
        }
        catch(SecurityException secureException)
        {
            Console.WriteLine("{0}: Permission to set Principal " +
                "is denied.", secureException.GetType().Name);
        }

        IPrincipal threadPrincipal = Thread.CurrentPrincipal;
        Console.WriteLine("Name: {0}\nIsAuthenticated: {1}" +
            "\nAuthenticationType: {2}", 
            threadPrincipal.Identity.Name, 
            threadPrincipal.Identity.IsAuthenticated,
            threadPrincipal.Identity.AuthenticationType);
    }
}

import System.*;
import System.Security.*;
import System.Security.Permissions.*;
import System.Security.Principal.*;
import System.Threading.*;
import System.Threading.Thread;
import System.Security.SecurityManager;

// Request permission to set thread principal.
/** @class.assembly SecurityPermissionAttribute(SecurityAction.RequestOptional,
     ControlPrincipal = true)
 */

class Principal
{
    public static void main(String[] args)
    {
        String rolesArray[] = new String[] { "managers", "executives" };

        try {
            // Set the principal to a new generic principal.
            Thread.set_CurrentPrincipal(new GenericPrincipal
                (new GenericIdentity("Bob", "Passport"), rolesArray));
        }
        catch (SecurityException secureException) {
            Console.WriteLine("{0}: Permission to set Principal " +
                "is denied.", secureException.GetType().get_Name());
        }

        IPrincipal threadPrincipal = Thread.get_CurrentPrincipal();
        Console.WriteLine("Name: {0}\nIsAuthenticated: {1}" +
            "\nAuthenticationType: {2}",
            threadPrincipal.get_Identity().get_Name(),
            String.valueOf(threadPrincipal.get_Identity().get_IsAuthenticated()
            ),threadPrincipal.get_Identity().get_AuthenticationType());
    } //main
} //Principal

Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0
Mostrar:
© 2014 Microsoft