This documentation is archived and is not being maintained.
Thread::CurrentPrincipal Property
Visual Studio 2010
Gets or sets the thread's current principal (for role-based security).
Assembly: mscorlib (in mscorlib.dll)
public: static property IPrincipal^ CurrentPrincipal { IPrincipal^ get (); void set (IPrincipal^ value); }
Property Value
Type: System.Security.Principal::IPrincipalAn IPrincipal value representing the security context.
| Exception | Condition |
|---|---|
| SecurityException | The caller does not have the permission required to set the principal. |
The following code example shows how to set and retrieve the principal of a thread.
using namespace System; using namespace System::Security; using namespace System::Security::Permissions; using namespace System::Security::Principal; using namespace System::Threading; int main() { array<String^>^rolesArray = {"managers","executives"}; try { // Set the principal to a new generic principal. Thread::CurrentPrincipal = gcnew GenericPrincipal( gcnew 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.ToString(), threadPrincipal->Identity->AuthenticationType ); }
- SecurityPermission
to manipulate the principal object. Associated enumeration: SecurityPermissionFlag::ControlPrincipal.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: