使用C#中的属性检查用户的授权

使用C#中的属性检查用户的授权,c#,attributes,authorization,C#,Attributes,Authorization,我想检查当前用户是否有权执行此操作的方法授权 以下是我拥有的属性的示例: [AttributeUsageAttribute(AttributeTargets.Method)] public class IsAuthorized : Attribute { public IsAuthorized(Rights right) { bool isAuthorized = false; if (right == Rights.None)

我想检查当前用户是否有权执行此操作的方法授权

以下是我拥有的属性的示例:

[AttributeUsageAttribute(AttributeTargets.Method)]
public class IsAuthorized : Attribute
{
    public IsAuthorized(Rights right)
    {
        bool isAuthorized = false;

        if (right == Rights.None)
            isAuthorized = true;
        else
        {
            DataAccessLayer.IDAL dal = new DataAccessLayer.DAL();
            string userName = Thread.CurrentPrincipal.Identity.Name;
            Guid userID = dal.GetUserIDFromUserName(userName);

            isAuthorized = dal.HasRight(userID, right.ToString());
        }

        if (!isAuthorized)
            throw new SecurityException("You don't have the rights to perform this action");
    }
}
这就是我检查用户是否有权访问该方法的方式:

[IsAuthorized(Rights.CreateUserGroup)]
public string Ping()
{
   return "The service is online";
}

哪种技术?MVC?ASP.NET?WPF?听起来像是一个很有潜力的工作。这也让我想起了CAS。尽管我不确定是否同意将权限烘焙到代码的元数据中,而不是使用无代码配置路由。我使用的是WCF web服务