如何设置mvc的role和user

1、总算将《css设计彻底研究》扫了一遍。以后专心后台。

2、

Css中的颜色表示法:六种

color:blue;

color:#0000ff;

color:#00f;(上一种的缩写)

color:rgb(0,0,255);

color:rgb(0%,0%,100%);

加粗:font-weight:normal   //正常

      font-weight:bold     //加粗

倾斜的两种方式:italic,oblique

分别是font-style:oblique,font-style:italic

 但是在windows中,两种倾斜的方式看起来效果是一样的。

3、如何实现角色和成员管理

在一个类或方法(一般使用方法)上设置 Authorize 特性,再加上参数,如

[Authorize(Roles = ("Admin,SuperAdmin"),(Users="Jack,Tom"))] 

用户就是注册时的用户,这个比较好设置。而Roles则必须写一个类,继承抽象类System.Web.Security.RoleProvider,并重写里面的方法,特别是GetRolesForUser和IsUserInRole。例如:

       public override string[] GetRolesForUser(string username)
        {
            List<string> roles = new List<string>();

            var admin = new AdminBLL().GetByWWId(username);

            if (admin != null)

            {
                roles.Add(admin.TypeId);
                return roles.ToArray();
            }

            var boss = new BossBLL().GetByWWID(username);
            if (boss != null && boss.WWId != string.Empty)
            {
                roles.Add("Boss");
            }
            return roles.ToArray();
        }
        public override bool IsUserInRole(string username, string roleName)
        {
            var admin = new AdminBLL().GetByWWId(username);
            if (admin != null)
            {
                return admin.TypeName == roleName;
            }
            else
            {
                var boss = new BossBLL().GetByWWID(username);
                if (boss != null)
                {
                    return roleName == "Boss";
                }
                else
                {
                    return false;
                }
            }
        }

4、当用ViewBag传值时,在后台可以不做非空判断l。渲染到前台后,如果没有相应的值,其值为null。

原文地址:https://www.cnblogs.com/Benjamin/p/2746925.html