简体   繁体   English

Angular 2中基于角色的UI

[英]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. 现在,我首先要问的是执行此操作的最佳实践是什么,如何实现它,并且存在任何示例示例,因为我无法根据自己的要求找到它。

Image 图片

在此处输入图片说明

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.

相关问题 Angular 8 基于角色的视图指令 - Angular 8 Directive for role based views Angular2中基于角色的访问控制? - Role Based Access Control in Angular2? 相同的URL路径,但根据用户角色加载不同的组件-Angular - Same URL path but loading different components based on User role - Angular 有没有办法让我在成功登录 angular 6 后创建基于角色的访问 - Is there a way for me to create role based access after successfully login in angular 6 如何根据 angular 中的当前用户角色导入 svg - How to import an svg based on the current user role in angular Angular14 中基于角色的菜单项和路由? - Role Based Menu Item and routing in Angular14? 如何在jhipster打字稿文件angular 5中根据用户角色检查条件 - How to check condition based on user role in jhipster typescript file angular 5 在 Angular 中 -&gt; 如何检查用户是否具有使用基于角色的访问权限且角色保存在数据库中的权限 - In Angular -> how to check if the user has permission using role-based access with the role save in the data base 基于角色的重定向 - Role based redirecting 访问管理组件正在使用 jwtHelper 在 angular 中实现基于角色的身份验证 - Access to the admin component am implementing role based authentication in angular using jwtHelper
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM