In ASP.NET MVC 2, to secure controller action, i have created a class RequirePermission
inherited from ActionFilterAttribute
class. The controller action looks like
[RequirePermission(permissions="CanView")]
public ActionResult List()
{
...
}
I have an enum with name Permissions
public enum Permissions { CanDoEdit, CanView, CanInsert }
The RequirePermission
class looks like
public class RequirePermission : ActionFilterAttribute
{
public string permissions;
string[] param = { "," };
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string[] requirePermissions = permissions.Split(param, StringSplitOptions.RemoveEmptyEntries);
if (requirePermissions.Contains(Permissions.CanDoEdit.ToString()))
{
//Check permission
}
if (requirePermissions.Contains(Permissions.CanView.ToString()))
{
//Check permission
}
if (requirePermissions.Contains(Permissions.CanInsert.ToString()))
{
//Check permission
}
}
}
Now instead of making different attributes , I want to use RequirePermission
attribute like
[RequirePermission(permissions=Permissions.CanView+","+Permissions.CanEdit)]
so that i can use it for different scenerious. but the compiler throw the following error.
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type