I am working on implementing user right management on an mvc3 application.
I have defined my action methods on database with ControllerName, ActionName, and Parameters consists ParameterName and ParameterType etc.
I implemented a custom attribute which inherited from Authorize attribute.
What i am trying to do is finding the action executing among my built-in actions defined on database and calculating if user has permission on specified action or not.
The code is like this;
[HttpPost]
[MyAuthorize]
public ActionResult Edit(VendorPageItem entity)
{
//...
}
public class MyAuthorize: System.Web.Mvc.AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext == null)
throw new ArgumentNullException("httpContext");
string controller = httpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
string action = httpContext.Request.RequestContext.RouteData.Values["action"].ToString();
int userId = SessionState.Current.LoginParameter.VendorUserID;
List<string> parameterTypes = new List<string>();
//TODO: Find out action method parameter types.
return IoCWorker.Resolve<IUserRightService>().HasUserRightToAction(userId, controller, action, parameterTypes);
}
}
My problem is finding the method parameter types in my custom attribute.
Thanks.
edit: forgot to mention that is post action. [HttpPost] added.
AuthorizeAttributethis way, but have found that it's easier just to check permissions in the controller method.