【发布时间】:2015-06-13 15:20:53
【问题描述】:
我自定义了 Asp.Net 的 authorize 属性,但是当我将属性设置为方法时,我不知道如何获取我设置为属性的角色或班级
例如我有这个 CustomeAuthorizeAttribute
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class CustomeAuthorizeAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (HttpContext.Current.User.Identity.IsAuthenticated && HttpContext.Current.User.IsInRole("Super"))
{
return true;
}
else
return false;
}
}
但是当我将角色设置为这样的属性时,我不知道如何获取角色
[CustomeAuthorizeAttribute(Roles="admin,super-admin")]
【问题讨论】:
标签: asp.net asp.net-authorization asp.net-authentication custom-authentication