[英]Role Based UI in Angular 2
I am developing an application in angular 2 with asp.net mvc 5 in which there are two kind of user one is super admin other is admin. 我正在使用asp.net mvc 5在angular 2中开发一个应用程序,其中有两种用户,一种是超级管理员,另一种是管理员。 I want to show all functionalities to super admin but I need to show some of its functionalities to the admin.
我想向超级管理员展示所有功能,但我需要向管理员展示其某些功能。 Now I want to ask that first what is the best practice for doing this and how I can achieve it and any sample example is there because I can't find it according to my requirements.
现在,我首先要问的是执行此操作的最佳实践是什么,如何实现它,并且存在任何示例示例,因为我无法根据自己的要求找到它。
for example If user logged in it redirect to this page. 例如,如果用户登录,它将重定向到此页面。 If the user is 'admin' then it show just table and if the user is 'super admin' then it show invite button as well as table too.
如果用户为“ admin”,则仅显示表格;如果用户为“ super admin”,则其同时显示邀请按钮和表格。
you need to roll your own mvc5 server side solution, you may find many examples on the internet, using extended methods like the following, you are able to check permissions via razor/c# and it will output html with the proper angular markup based on the user/role. 您需要推出自己的mvc5服务器端解决方案,您可能会在Internet上找到许多示例,使用类似以下的扩展方法,您可以通过razor / c#检查权限,并且它将基于html输出带有正确角度标记的html用户/角色。
public static bool UserHasPermission(this ControllerBase controller, string permissionString)
{
bool permissionFound = false;
try
{
permissionFound = new RoleUserCheck(controller.ControllerContext.HttpContext.User.Identity.Name).UserHasPermission(permissionString);
}
catch { }
return permissionFound;
}
then on your partial/view you may access the function via razor markup. 那么您可以在局部/视图上通过剃刀标记访问该功能。
@{
if (ViewContext.Controller.UserHasPermission("DeleteWithPaymentRollback"))
{
<button type="button" (click)="showconfirm()" class="btn btn-danger btn-xs">
<span class="fa fa-recycle"></span>
</button>
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.