Пример #1
0
        // 只需重载此方法,模拟自定义的角色授权机制
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            string username;

            username = httpContext.User.Identity.Name;
            string group;
            if (httpContext.Session["Group"] == null)
            {
                DbModelDataContext db = new DbModelDataContext(conStr);
                try
                {
                    group = db.SIS_User.Single(u => u.Username == username).SIS_UserGroup.GroupName;
                }
                catch
                {
                    return false;
                }

            }
            else
            {
                group = httpContext.Session["Group"].ToString();
            }

            if (group == "admin")
            {
                return true;
            }
            return false;
        }
Пример #2
0
 public static DbModelDataContext Create()
 {
     DbModelDataContext db = new DbModelDataContext(conStr);
     return db;
 }