using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Security;
using System.Security.Permissions;
using System.Security.Principal;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
//角色数组
string[] rolesArray = { "managers", "executives" };
try
{
// Set the principal to a new generic principal.
//thread,currentprincipal是获取或设置线程的用户(当前负责人)
//返回类型为iprincipal接口类型
Thread.CurrentPrincipal =
new GenericPrincipal(new GenericIdentity(
"Bob", "xx"), rolesArray);//Passport
}
catch (SecurityException secureException)
{
Console.WriteLine("{0}: Permission to set Principal " +
"is denied.", secureException.GetType().Name);
}
//把上面加工的变量引用供给threadprincal
IPrincipal threadPrincipal = Thread.CurrentPrincipal;
Console.WriteLine("Name: {0}\nIsAuthenticated: {1}" +
"\nAuthenticationType: {2}",
threadPrincipal.Identity.Name,//name用户名
threadPrincipal.Identity.IsAuthenticated,//是否通过认证
threadPrincipal.Identity.AuthenticationType);//验证方式
Console.ReadKey();
}
}
}
小结:
只是摘录于此,也是半懂不懂,或者说完全不懂.
适用的场合在何处?
TCBS用到了