當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Thread.CurrentPrincipal屬性代碼示例

本文整理匯總了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
開發者ID:VB.NET開發者,項目名稱:System.Threading,代碼行數:35,代碼來源:Thread.CurrentPrincipal

示例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
開發者ID:VB程序員,項目名稱:System.Threading,代碼行數:26,代碼來源:Thread.CurrentPrincipal


注:本文中的System.Threading.Thread.CurrentPrincipal屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。