如何在我的自定义FeatureAuthorize属性中使用按位OR运算传递多个参数,同样AttributeUsage支持AttributeTarget方法或类.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
Run Code Online (Sandbox Code Playgroud)
以下是我想要实现的示例,提供的任何功能,无论是发送钱还是收款方法都应该是可访问的.
[FeatureAuthorize(Feature = EnumFeature.SendMoney | EnumFeature.ReceiveMoney)]
public ActionResult SendOrReceiveMoney(int? id, EnumBankAccountType? type)
{
// My code
}
Run Code Online (Sandbox Code Playgroud)
FeatureAuthorize属性的主体就像.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class FeatureAuthorizeAttribute : AuthorizeAttribute
{
public EnumFeature Feature { get; set; }
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (!IsFeatureAllowed(Feature)) // Verification in database.
{
// Redirection to not authorize page.
}
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.