本文整理汇总了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