mikha
asked on
custom authorization on controller action and HTML in asp.net mvc
I'm implementing custom authorize attribute in asp.net mvc. I am saving user permissions in a table and created enumeration for it.
in the controller, i Use the attribute on each action method.
but i want to extend it such that, i can apply the permissions to HTML elements as well. say for example,
I have a create new button and i want to display it only if the current user has "create" permission.
is there a way to achieve this. what would be a good way to approach this?
in my CustomAuthorize class, i'm also inheriting from the IActionFilter, to see if i can use it someway to achieve this.
Public enum permissions { create, view , edit ....}
public class CustomAuthorize : AuthorizeAttribute, IActionFilter {
protected override bool AuthorizeCore(HttpContextB ase context){
//database call to get the user permissions
}
}
in the controller, i Use the attribute on each action method.
but i want to extend it such that, i can apply the permissions to HTML elements as well. say for example,
I have a create new button and i want to display it only if the current user has "create" permission.
is there a way to achieve this. what would be a good way to approach this?
in my CustomAuthorize class, i'm also inheriting from the IActionFilter, to see if i can use it someway to achieve this.
Public enum permissions { create, view , edit ....}
public class CustomAuthorize : AuthorizeAttribute, IActionFilter {
protected override bool AuthorizeCore(HttpContextB
//database call to get the user permissions
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.