I have function which return true or false depend of UserID and User Role.
I have controller with several action results.
for example
public class DemoController : Controller
{
public ActionResult Index(){}
public ActionResult Contact(){}
}
So i want , everytime when user use this actions, to check if user is in role.
I know i can make it like
[Authorize(Roles = "Administrator")]
public ActionResult JustAdmins(){}
But this kind of way, everytime user visit this action, its an extra SQL Query.
My want to store user role in MemCached so my function will be like
public static bool IsCompany(Guid UserID)
{
//if (get from cache != null && get from cache == "Role")
// return true
//if (get from DB != null && get from DB == "Role")
//return true
return false;
}
But how i can inherit all Action in my controller to check this function ?
tip: maybe override OnActionExecuting or similar ?