代码:
private void button1_Click_1(object sender, EventArgs e)
{
GenericIdentity identity = new GenericIdentity("HU");
GenericPrincipal principal = new GenericPrincipal(identity, new string[] { "1", "2", "3" });
Thread.CurrentPrincipal = principal;
if (Thread.CurrentPrincipal.IsInRole("1"))
{
Console.WriteLine("有权限");
}
}

本文展示了一个使用C#进行权限验证的代码示例。通过创建GenericIdentity和GenericPrincipal对象,将特定的角色分配给线程,并检查线程是否属于特定角色,以此来实现权限验证。

被折叠的 条评论
为什么被折叠?



