zoukankan      html  css  js  c++  java
  • 页面权限设计思路简析

    1、用户对象设计

     1     public class User
     2     {
     3         public string UserName { get; set; }
     4         public string Password { get; set; }
     5         //权限管理
     6         public List<string> Permission { get; private set; }
     7         public bool CheckPermission(string code)
     8         {
     9             if (this.Permission != null && this.Permission.Contains(code))
    10             {
    11                 return true;
    12             }
    13             return false;
    14         }
    15         /// <summary>
    16         /// 加入权限
    17         /// </summary>
    18         /// <param name="code"></param>
    19         public void SetPermission(string code)
    20         {
    21             if (this.Permission == null)
    22             {
    23                 this.Permission = new List<string>();
    24             }
    25             this.Permission.Add(code);
    26         }
    27     }

    2、扩展Html.Authorize(扩展方法)

        public static class AuthorizeExtensions
        {
            public static bool IsAuthorized(this HtmlHelper helper, string permissionCode)
            {
                return UserService.GetCurrentUser().CheckPermission(permissionCode);
            }
    
            public static string Authorize(this string html, string permissionCode)
            {
                if (UserService.GetCurrentUser().CheckPermission(permissionCode);)
                {
                    return html;
                }
                else
                {
                    return string.Empty;
                }
            }
    
    
            public static IHtmlString Authorize(this IHtmlString html, string permissionCode)
            {
                if (UserService.GetCurrentUser().CheckPermission(permissionCode);)
                {
                    return html;
                }
                else
                {
                    return MvcHtmlString.Empty;
                }
            }
        }

    3、用例

    1                             @if (Html.IsAuthorized(Utility.AuthConst.IcsonCodeAddVirtualQty))
    2                             {
    3                                    <a onclick="XX">
    4                                         查看</a>
    5                             }
    人总要去积累生活、工作上的点点滴滴,慢慢的进步,以后回头看看,笑笑,顺便学学,人都说回忆才是最美的。
  • 相关阅读:
    free pascal dialect
    free pascal
    free pascal
    跳槽后在新公司的一点感悟
    安全攻防技能30讲
    设计模式之美(二)——设计模式
    设计模式之美(一)——设计原则、规范与重构
    数据结构和算法躬行记(8)——动态规划
    倾斜摄影实景三维在智慧工厂 Web 3D GIS 数字孪生应用
    智慧文旅促进旅游业发展,可视化带你云游武夷
  • 原文地址:https://www.cnblogs.com/jueye/p/3084136.html
Copyright © 2011-2022 走看看