using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Principal;
using System.Threading;
// c#-安全性-身份验证授权
namespace ConsoleApp26
{
class Program
{
// Identity = 身份
static void Main(string[] args)
{
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;
WindowsIdentity identity = (WindowsIdentity)principal.Identity;
Console.WriteLine("身份:" + identity);
Console.WriteLine("名称:"+identity.Name);
Console.WriteLine("user:?{0}", principal.IsInRole(WindowsBuiltInRole.User));
Console.WriteLine("admianstrators:?{0}", principal.IsInRole(WindowsBuiltInRole.Administrator));
Console.WriteLine("已经认证:{0}", identity.IsAuthenticated);
Console.WriteLine("认证类型:{0}", identity.AuthenticationType);
Console.WriteLine("是否匿名?{0}", identity.IsAnonymous);
Console.WriteLine("标识:{0}", identity.Token);
Console.ReadLine();
}
}
}
c#-安全性-身份验证授权
最新推荐文章于 2024-05-02 06:42:41 发布