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                             }
    人总要去积累生活、工作上的点点滴滴,慢慢的进步,以后回头看看,笑笑,顺便学学,人都说回忆才是最美的。
  • 相关阅读:
    Android学习笔记:TabHost 和 FragmentTabHost
    JS兼容性处理
    【题解】数颜色--带修改莫队
    技巧--对拍
    学习笔记--数论--莫比乌斯反演初认识
    【题解】售票系统--一道毒瘤题
    【题解】P3391 文艺平衡树
    学习笔记--计算几何
    题解 P2661 【信息传递】
    学习笔记--简化剩余系与欧拉函数φ( )
  • 原文地址:https://www.cnblogs.com/jueye/p/3084136.html
Copyright © 2011-2022 走看看