No, you don't have to do that. How you determine the privileges of each user can be either done within OnAuthorization
or refactored into a separate static method and called within OnAuthorization
.
But, when you use use the custom authorize attribute for either Action
method or for a Controller
, you should be able to say that only users with Create
permission can access the Action
or users with Read
permission can access this controller
. Please take a look at this blog post.
http://codeutil.wordpress.com/2013/05/14/forms-authentication-in-asp-net-mvc-4/#mvc-implement-custom-authorization-filter
you will notice there are two Variables defined
public int StartTime { get; set; }
public int EndTime { get; set; }
instead, you can use
public bool AllowRead {get;set;}
public bool AllowWrite {get;set;}
then use the authorize attribute as follows
[HttpPost]
[CustomAuthorize(AllowRead = false, AllowWrite = true)]
public ActionResult Create(Model model)
{
//your code
}
above is just one way of doing it. Another method is to use an enum flag. Please take a look at this answer.
How could I use my own database table for MVC 4 user control (and authorizing with boolean fields in role table)?