GenericPrincipal-Konstruktor
Initialisiert eine neue Instanz der GenericPrincipal-Klasse aus einer Benutzeridentität und einem Array mit den Namen der Rollen, zu denen der von dieser Identität dargestellte Benutzer gehört.
Namespace: System.Security.Principal
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub New ( _
identity As IIdentity, _
roles As String() _
)
'Usage
Dim identity As IIdentity
Dim roles As String()
Dim instance As New GenericPrincipal(identity, roles)
public GenericPrincipal (
IIdentity identity,
string[] roles
)
public:
GenericPrincipal (
IIdentity^ identity,
array<String^>^ roles
)
public GenericPrincipal (
IIdentity identity,
String[] roles
)
public function GenericPrincipal (
identity : IIdentity,
roles : String[]
)
Parameter
- identity
Eine grundlegende Implementierung der IIdentity-Schnittstelle, die einen beliebigen Benutzer darstellt.
- roles
Ein Array mit Namen von Rollen, zu denen der durch den identity-Parameter dargestellte Benutzer gehört.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
Der identity-Parameter ist NULL (Nothing in Visual Basic). |
Beispiel
Im folgenden Code wird die Verwendung des GenericPrincipal-Konstruktors veranschaulicht. Dieses Codebeispiel ist Teil eines umfangreicheren Beispiels für die GenericPrincipal-Klasse.
Dim roles(10) As String
Dim windowsIdentity As WindowsIdentity = windowsIdentity.GetCurrent()
If (windowsIdentity.IsAuthenticated) Then
' Add custom NetworkUser role.
roles(0) = "NetworkUser"
End If
If (windowsIdentity.IsGuest) Then
' Add custom GuestUser role.
roles(1) = "GuestUser"
End If
If (windowsIdentity.IsSystem) Then
' Add custom SystemUser role.
roles(2) = "SystemUser"
End If
' Construct a GenericIdentity object based on the current Windows
' identity name and authentication type.
Dim authenticationType As String = windowsIdentity.AuthenticationType
Dim userName As String = windowsIdentity.Name
Dim genericIdentity = _
New GenericIdentity(userName, authenticationType)
' Construct a GenericPrincipal object based on the generic identity
' and custom roles for the user.
Dim genericPrincipal As New GenericPrincipal(genericIdentity, roles)
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
string[] roles = new string[10];
if (windowsIdentity.IsAuthenticated)
{
// Add custom NetworkUser role.
roles[0] = "NetworkUser";
}
if (windowsIdentity.IsGuest)
{
// Add custom GuestUser role.
roles[1] = "GuestUser";
}
if (windowsIdentity.IsSystem)
{
// Add custom SystemUser role.
roles[2] = "SystemUser";
}
// Construct a GenericIdentity object based on the current Windows
// identity name and authentication type.
string authenticationType = windowsIdentity.AuthenticationType;
string userName = windowsIdentity.Name;
GenericIdentity genericIdentity =
new GenericIdentity(userName, authenticationType);
// Construct a GenericPrincipal object based on the generic identity
// and custom roles for the user.
GenericPrincipal genericPrincipal =
new GenericPrincipal(genericIdentity, roles);
WindowsIdentity^ windowsIdentity = WindowsIdentity::GetCurrent();
array<String^>^roles = gcnew array<String^>(10);
if ( windowsIdentity->IsAuthenticated )
{
// Add custom NetworkUser role.
roles[ 0 ] = L"NetworkUser";
}
if ( windowsIdentity->IsGuest )
{
// Add custom GuestUser role.
roles[ 1 ] = L"GuestUser";
}
if ( windowsIdentity->IsSystem )
{
// Add custom SystemUser role.
roles[ 2 ] = L"SystemUser";
}
// Construct a GenericIdentity object based on the current Windows
// identity name and authentication type.
String^ authenticationType = windowsIdentity->AuthenticationType;
String^ userName = windowsIdentity->Name;
GenericIdentity^ genericIdentity = gcnew GenericIdentity(
userName,authenticationType );
// Construct a GenericPrincipal object based on the generic identity
// and custom roles for the user.
GenericPrincipal^ genericPrincipal = gcnew GenericPrincipal(
genericIdentity,roles );
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
String roles[] = new String[10];
if (windowsIdentity.get_IsAuthenticated()) {
// Add custom NetworkUser role.
roles.set_Item(0, "NetworkUser");
}
if (windowsIdentity.get_IsGuest()) {
// Add custom GuestUser role.
roles.set_Item(1, "GuestUser");
}
if (windowsIdentity.get_IsSystem()) {
// Add custom SystemUser role.
roles.set_Item(2, "SystemUser");
}
// 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 genericIdentity = new GenericIdentity(userName,
authenticationType);
// Construct a GenericPrincipal object based on the generic identity
// and custom roles for the user.
GenericPrincipal genericPrincipal = new GenericPrincipal(genericIdentity,
roles);
Plattformen
Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
GenericPrincipal-Klasse
GenericPrincipal-Member
System.Security.Principal-Namespace