未完待续...
案例1:按钮权限校验,无权限不显示,利用TagHelper控制元素是否显示
[HtmlTargetElement("tc-permission", TagStructure = TagStructure.NormalOrSelfClosing)] public class TCPermissionTagHelper : TagHelper { private IPermissionContext permissionContext = null; public TCPermissionTagHelper(IPermissionContext permissionContext) { this.permissionContext = permissionContext; } public string[] Permissions { get; set; } public string Permission { get; set; } public override void Process(TagHelperContext context, TagHelperOutput output) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } output.TagName = null; if (!string.IsNullOrEmpty(Permission)) { Permissions = Permission.SplitToArray<string>(); } //HasPermission:根据UserID、按钮权限编码判断用户是否有此按钮权限,如果无权就不输出 if (Permissions == null || Permissions.Length == 0 || !permissionContext.HasPermission(Permissions)) { output.SuppressOutput(); return; } } }
页面中添加:
<tc-permission permission="@Permissions.系统模块.账户管理.添加"> <a id="btnAdd" class="btn btn-primary" onclick="cache.add(); return false;">添加</a> </tc-permission>