【发布时间】:2018-12-04 02:04:51
【问题描述】:
如何在我的自定义FeatureAuthorize 属性中使用按位或运算传递多个参数,同样AttributeUsage 支持AttributeTarget 作为方法或类。
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
以下是我想要实现的示例,提供的任何功能都应该可以访问,无论是汇款还是收款方法。
[FeatureAuthorize(Feature = EnumFeature.SendMoney | EnumFeature.ReceiveMoney)]
public ActionResult SendOrReceiveMoney(int? id, EnumBankAccountType? type)
{
// My code
}
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.
}
}
}
提前致谢。
【问题讨论】:
标签: c# asp.net-mvc bitwise-or