1

I'm using MVC 4.

I code this customer attribute that inherits from System.Web.Mvc.ActionFilterAttribute

public class AuthorizedAttribute : ActionFilterAttribute
{    
    public AccessLevel Threshold { get; set; }

    public AuthorizedAttribute()
    {
        Threshold = AccessLevel.Anonymous;
    }

    public AuthorizedAttribute(AccessLevel threshold)
    {
        Threshold = threshold;
    }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        //some actions
        base.OnActionExecuting(filterContext);
    }
}

And I'm using it on action Manage in my UserController

public class UserController : Controller
{
    [HttpGet]
    [Authorized(AccessLevel.Administrator)]
    public ViewResult Manage()
    {
         return View();
    }
}

I put a breakpoint in my attribute contructor, in the overrided method OnActionExecuting and in my UserController and when I call the action url through my browser in debug mode only my controller breakpoint is firing and I land on the page even I'm not authenticated.. What am I doing wrong ?

Thank in advance.

MrGrabazu
  • 95
  • 1
  • 9

2 Answers2

0

Your code should work. Probably you have troubles in the routing or etc.

Sergey
  • 471
  • 3
  • 10
0

It appear that I wasn't completly in MVC 4 but almost in MVC 5. I just need to do a little update on my web.config to resolve my issue.. I found my salvation here

MrGrabazu
  • 95
  • 1
  • 9