示例#1
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var cc = context.HttpContext.Request.Path;

            string[] bb        = cc.ToString().Split('/');
            string   homebase  = bb[2].ToString();
            string   actionstr = bb[3].ToString();

            if (homebase.ToLower().Equals("instruct") && !actionstr.ToLower().Equals("stop"))///判断访问模块为设备交互模块
            {
                string        devicesn   = context.HttpContext.Request.Query["sn"].ToString();
                List <string> devicesnls = (List <string>)CacheHelperNetCore.CacheValue("device"); //从内存中获取设备列表缓存
                if (devicesnls == null || !devicesnls.Contains(devicesn))                          //当请求的编码不在缓存中
                {
                    Device device = deviceDao.getBySn(devicesn);
                    if (device.id != null)
                    {
                        if (devicesnls == null)
                        {
                            devicesnls = new List <string>();
                        }
                        devicesnls.Add(devicesn);
                        CacheHelperNetCore.CacheInsert("device", devicesnls);
                    }
                    else
                    {
                        JsonResult result = new JsonResult("invalid sn!");//非法设备
                        context.Result = result;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public User login(string account, string pwd)
        {
            string      jmpwd  = EncryptProvider.Md5(pwd);
            string      sql    = "select * from public.user where account='" + account + "' and pwd='" + jmpwd + "'";
            List <User> userls = dbdao.DbSql <User>(sql);

            if (userls.Count > 0)
            {
                log.Info("用户登录:" + account + " 时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:sss"));
                CacheHelperNetCore.CacheInsertFromMinutes("cache", userls[0].id.ToString(), 10);
                User user = (User)userls[0];
                return(user);
            }
            else
            {
                return(null);
            }
        }