当前位置: 首页>>代码示例>>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;未经允许,请勿转载。