i’m trying to create an attribute that i can set on my controllers action in which i can check if a user in some kind of role.
I know with standard asp.net authentication this is already possible, but i’m not using that.
So what i want to accomplish is this:
[Role("Admin", "SuperUser")]
public ActionResult SafeCourse()
I’ve constructed this:
public class AdminAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Ans now….. i want to redirect the user to some controller/action or if that isn’t possible to some view when he / she is not in the right role.
But i’m not in my usual context (= controller) and i’m somewhat lost 🙂
Michel
If you make your action filter implement
IAuthorizationFilterit will execute before other types … then inOnAuthorization(AuthorizationContext filterContext)set the result.Something like
Kindness,
Dan