本文整理匯總了VB.NET中System.Threading.Thread.CurrentPrincipal屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET Thread.CurrentPrincipal屬性的具體用法?VB.NET Thread.CurrentPrincipal怎麽用?VB.NET Thread.CurrentPrincipal使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Threading.Thread
的用法示例。
在下文中一共展示了Thread.CurrentPrincipal屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Principal
Option Explicit
Option Strict
Imports System.Security
Imports System.Security.Permissions
Imports System.Security.Principal
Imports System.Threading
Public Class Principal
<MTAThread> _
Shared Sub Main()
Dim rolesArray As String() = {"managers", "executives"}
Try
' Set the principal to a new generic principal.
Thread.CurrentPrincipal = _
New GenericPrincipal(New GenericIdentity( _
"Bob", "Passport"), rolesArray)
Catch secureException As SecurityException
Console.WriteLine("{0}: Permission to set Principal " & _
"is denied.", secureException.GetType().Name)
End Try
Dim threadPrincipal As IPrincipal = Thread.CurrentPrincipal
Console.WriteLine( _
"Name: {0}" & vbCrLf & "IsAuthenticated:" & _
" {1}" & vbCrLf & "AuthenticationType: {2}", _
threadPrincipal.Identity.Name, _
threadPrincipal.Identity.IsAuthenticated, _
threadPrincipal.Identity.AuthenticationType)
End Sub
End Class
示例2: Module1
' 導入命名空間
Imports System.Threading
Module Module1
Sub Main()
Dim objThread As Thread
objThread = Thread.CurrentThread
With objThread
Console.WriteLine("Apartment State: {0}", .ApartmentState)
Console.WriteLine("Current Context: {0}", .CurrentContext)
Console.WriteLine("Current Culture: {0}", .CurrentCulture)
Console.WriteLine("Current Principal: {0}", .CurrentPrincipal)
Console.WriteLine("Current Thread: {0}", .CurrentThread)
Console.WriteLine("Current UI Culture: {0}", .CurrentUICulture)
Console.WriteLine("Is Alive: {0}", .IsAlive)
Console.WriteLine("Is Background: {0}", .IsBackground)
Console.WriteLine("Is Thread Pool Thread: {0}", .IsThreadPoolThread)
Console.WriteLine("Name: {0}", .Name)
Console.WriteLine("Priority: {0}", .Priority)
Console.WriteLine("Thread State: {0}", .ThreadState)
End With
End Sub
End Module