asp.net mvc - mvc.net custom [Authorize] attribute -
i working mvc4 in project, simplemembership role provider. need implement task based access in project. actionresult([httppost]) consist of create,get,update , delete methods. implemented custom authorize class is...
public class authorizeuserattribute : authorizeattribute { // custom property public string accesslevel { get; set; } protected override bool authorizecore(httpcontextbase httpcontext) { var isauthorized = base.authorizecore(httpcontext); if (!isauthorized) { return false; } string privilegelevels = string.join("", objmanager.getpermissions()); // call method rights of user db(view,delete,update,create) if (privilegelevels.contains(this.accesslevel)) { return true; } else { return false; } } protected override void handleunauthorizedrequest(authorizationcontext filtercontext) { //some code redirect request page , showing alert("you don't have permission action") through response. } }
i can't use [authorizeuser(accesslevel="get or delete or view or create")] on each actionresult. because implemented total view, create, update , delete functionality in 1 actionresult(which calls methods create, update, delete , view).
my problem when giving [authorizeuser(accesslevel="get")] methods, [authorizeuser(accesslevel="create")] create methods , on.... after control coming inside actionresult() checking first [authorizeuser(accesslevel="some access level")], once authorize, not checking other method [authorizeuser].
after trying [authorizeuser] on actionresult(), came conclude each page request checking authorization(not seconed time), there way call [authorizeuser(accesslevel="some access level")] more 1 time in single page request.
thanks in advance...
Comments
Post a Comment