GenericPrincipal(IIdentity, String[]) コンストラクター

定義

ユーザー ID と、その ID によって表されるユーザーが所属するロール名の配列から、GenericPrincipal クラスの新しいインスタンスを初期化します。

public:
 GenericPrincipal(System::Security::Principal::IIdentity ^ identity, cli::array <System::String ^> ^ roles);
public GenericPrincipal (System.Security.Principal.IIdentity identity, string[] roles);
public GenericPrincipal (System.Security.Principal.IIdentity identity, string[]? roles);
new System.Security.Principal.GenericPrincipal : System.Security.Principal.IIdentity * string[] -> System.Security.Principal.GenericPrincipal
Public Sub New (identity As IIdentity, roles As String())

パラメーター

identity
IIdentity

あらゆるユーザーを表す IIdentity の基本的な実装。

roles
String[]

identity パラメーターで表されるユーザーが所属するロール名の配列。

例外

identity パラメーターが null です。

次のコードは、 コンストラクターの使用方法を GenericPrincipal 示しています。 このコード例は、GenericPrincipal クラスのために提供されている大規模な例の一部です。

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.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);
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)

適用対象