你应该看看 PrincipalPermissionAttribute 类,这里是 MSDN 文档:
PrincipalPermissionAttribute 类 MSDN 文档
当 Thread.CurrentPrincipal 与安全断言不匹配时,PrincipalPermissionAttribute 会引发 SecurityException。
例子:
用户名为 GDroid:
[PrincipalPermission(SecurityAction.Demand, Name = "GDroid")]
public void YourBusinessMethod()
{
// Do something
}
用户属于管理员角色:
[PrincipalPermission(SecurityAction.Demand, Role = "Admin")]
public void YourBusinessMethod()
{
// Do something
}
用户已通过身份验证:
[PrincipalPermission(SecurityAction.Demand, Authenticated = true)]
public void YourBusinessMethod()
{
// Do something
}