Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

GenericPrincipal Constructor (IIdentity^, array<String^>^)

 

Initializes a new instance of the GenericPrincipal class from a user identity and an array of role names to which the user represented by that identity belongs.

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

public:
GenericPrincipal(
	IIdentity^ identity,
	array<String^>^ roles
)

Parameters

identity
Type: System.Security.Principal::IIdentity^

A basic implementation of IIdentity that represents any user.

roles
Type: array<System::String^>^

An array of role names to which the user represented by the identity parameter belongs.

Exception Condition
ArgumentNullException

The identity parameter is null.

The following code shows the use of the GenericPrincipal constructor. This code example is part of a larger example provided for the GenericPrincipal class.

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

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show:
© 2017 Microsoft