asp.net - getting Roles that already set to custom Authorization attribute? -
i customized authorize attribute of asp.net not know how roles set attribute when set attribute method or class
for example have 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; } }
but not know how roles when set them attribute
[customeauthorizeattribute(roles="admin,super-admin")]
by default inhirits roles property base authorize class can roles directly using roles property
for example
if (httpcontext.current.user.identity.isauthenticated && httpcontext.current.user.isinrole(roles)) { return true; }
or create new properties belong custom authorization attribute , use them.
Comments
Post a Comment