html5 - Hiding menu element by permission using AngularJS and Web API -


i have implemented roles based authorization in web api restfull service using owin.

what best way hide menu items or buttons based on role user has? want hide items user has no access to.

updated

i want know best practice controller.

this example of want, don't think right way it. second, routing fails because cannot distinguish between 2 actions.

[authorize(roles = "somerole")] public class foocontroller : apicontroller {     [httpget]     public string helloworld()     {          return "hello world - authorized";     }      [httpget]     [route("hasaccess")]     [allowanonymous]     public bool hasaccess()     {          return user.isinrole("somerole");     } } 

http://localhost:8080/api/foo/ --> calls helloworld()

http://localhost:8080/api/foo/hasaccess --> calls hasaccess()

you use ng-if directive. render div if hasrole function returns true.

<div ng-if="hasrole('admin')">                    admin menu item </div> 

and in controller have function

$scope.hasrole = function(role){     //check if user has needed role     //return true or false } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -