public override bool Set <T>(string key, T value, TimeSpan?expiry = default(TimeSpan?)) { var newValue = CacheCommon.ConvertJson <T>(value); _db.ListLeftPush(CacheCommon.AddSysCustomKey(sysRedisKey, key), newValue); return(true); }
public IActionResult Login(LoginInputModel model) { if (!ModelState.IsValid) { } string validateCode = (string)TempData["validateCode"]; if (!model.ValidateCode.Equals(validateCode)) { return(View()); } //bool result = false; //_userService.CheckLogin(model.UserName, model.Password); var user = _userService.GetAll().FirstOrDefault(r => r.UserName == model.UserName && r.Password == model.Password); if (user != null) { long userId = user.Id; HttpContext.Session.SetString("LoginUserId", userId.ToString()); HttpContext.Session.SetString("LoginUserName", user.UserName); var permissionNames = _roleService.GetPermissionByUser(userId).ToList()?.Select(r => r.Permission.PermissionName).ToList(); if (permissionNames != null) { CacheCommon.SetCache("permissionNames", permissionNames, TimeSpan.FromMinutes(30), true); } return(RedirectToAction("Index", "Home")); } return(View()); }
public override async Task <T> GetAsync <T>(string key, string dataKey) { var redisValue = await _db.HashGetAsync(CacheCommon.AddSysCustomKey(sysRedisKey, key), dataKey); if (string.IsNullOrWhiteSpace(redisValue)) { return(default(T)); } return(CacheCommon.ConvertObj <T>(redisValue)); }
public override bool Set <T>(string key, T value, TimeSpan?expiry = default(TimeSpan?)) { if (KeyExists(key)) { Remove(key); } var newValue = CacheCommon.ConvertJson <T>(value); return(expiry.HasValue ? mc.Set(CacheCommon.AddSysCustomKey(sysMemCacheKey, key), newValue, DateTime.Now.AddSeconds(expiry.Value.Seconds)) : mc.Set(CacheCommon.AddSysCustomKey(sysMemCacheKey, key), newValue)); }
public override async Task <bool> SetAsync <T>(string key, string dataKey, T value, TimeSpan?expiry = default(TimeSpan?)) { if (KeyExists(key)) { Remove(key); } var newValue = CacheCommon.ConvertJson <T>(value); return(await _db.HashSetAsync(CacheCommon.AddSysCustomKey(sysRedisKey, key), dataKey, newValue)); }
public override List <T> Get <T>(string key, double startScore, double endScore) { var redisValues = _db.SortedSetRangeByScore(CacheCommon.AddSysCustomKey(sysRedisKey, key), startScore, endScore); //zrangebyscore if (redisValues.Length <= 0) { return(default(List <T>)); } return(CacheCommon.ConvertObj <List <T> >(CacheCommon.ConvertJson(redisValues))); }
public override T Get <T>(string key) { var redisValue = _db.ListRightPop(CacheCommon.AddSysCustomKey(sysRedisKey, key)); if (string.IsNullOrWhiteSpace(redisValue)) { return(default(T)); } return(CacheCommon.ConvertObj <T>(redisValue)); }
public override bool Set <T>(string key, T value, TimeSpan?expiry = default(TimeSpan?)) { if (KeyExists(key)) { Remove(key); } var newValue = CacheCommon.ConvertJson <T>(value); return(_db.StringSet(CacheCommon.AddSysCustomKey(sysRedisKey, key), newValue, expiry)); }
public override bool Remove(string key) { if (KeyExists(key)) { HttpRuntime.Cache.Remove(CacheCommon.AddSysCustomKey(sysNetCacheKey, key)); return(true); } else { return(false); } }
public override bool Set <T>(string key, T value, string filePath, TimeSpan?expiry = default(TimeSpan?)) { var newValue = CacheCommon.ConvertJson <T>(value); if (expiry.HasValue) { HttpRuntime.Cache.Insert(CacheCommon.AddSysCustomKey(sysNetCacheKey, key), newValue, new CacheDependency(filePath), System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(expiry.Value.Seconds)); } else { HttpRuntime.Cache.Insert(key, value, new CacheDependency(filePath)); } return(true); }
public override T Get <T>(string key) { var value = mc.Get(CacheCommon.AddSysCustomKey(sysMemCacheKey, key)); if (value == null) { return(default(T)); } if (value is string) { var resultValue = mc.Get(CacheCommon.AddSysCustomKey(sysMemCacheKey, key)) as string; return(CacheCommon.ConvertObj <T>(resultValue)); } else { return((T)value); } }
public override T Get <T>(string key) { var value = HttpRuntime.Cache.Get(key); if (value == null) { return(default(T)); } if (value is string) { var resultValue = HttpRuntime.Cache.Get(key) as string; return(CacheCommon.ConvertObj <T>(resultValue)); } else { return((T)value); } }
public override long GetListLength(string key) { return(_db.ListLength(CacheCommon.AddSysCustomKey(sysRedisKey, key))); }
public override T Get <T>(string key, string dataKey) { var redisValue = _db.HashGet(CacheCommon.AddSysCustomKey(sysRedisKey, key), dataKey); return(CacheCommon.ConvertObj <T>(redisValue)); }
public override bool Set <T>(string key, T value, double score, TimeSpan?expiry = default(TimeSpan?)) { var newValue = CacheCommon.ConvertJson <T>(value); return(_db.SortedSetAdd(CacheCommon.AddSysCustomKey(sysRedisKey, key), newValue, score)); }
public override bool KeyExists(string key) { return(HttpRuntime.Cache.Get(CacheCommon.AddSysCustomKey(sysNetCacheKey, key)) != null ? true : false); }
public override async Task <bool> KeyExistsAsync(string key, string dataKey) { return(await _db.HashExistsAsync(CacheCommon.AddSysCustomKey(sysRedisKey, key), dataKey)); }
public override bool KeyExpire(string key, TimeSpan?expiry = default(TimeSpan?)) { return(_db.KeyExpire(CacheCommon.AddSysCustomKey(sysRedisKey, key), expiry)); }
public void OnAuthorization(AuthorizationFilterContext context) { //权限过滤的两种思路 认证过滤器和方法过滤器都可以 //一:在每个控制器和action上添加相应的特性标签,把标签名称存到数据库权限表中,获取当前请求控制器下的action的对应的特性标签 与数据库存储的进行对比,相同就是有权限 //二:把每个控制器和action以 ControllerName_ActionName 的形式存在数据库权限表中,获取当前访问的控制器名称和Action 名称与当前用户的所在角色下的权限进行比对 ,相同就是有权限 //return; //匿名标识 无需验证 if (context.Filters.Any(e => (e as AllowAnonymous) != null)) { return; } //和上面一样 var endpoint = context?.HttpContext?.GetEndpoint(); if (endpoint?.Metadata.GetMetadata <IAllowAnonymous>() != null) { return; } //不是控制器里的方法 无需验证 if (!context.ActionDescriptor.IsControllerAction()) { return; } #region 获取当前用户id和用户名判断是否登录和是否admin管理员 string userId = context.HttpContext.Session.GetString("LoginUserId"); string userName = context.HttpContext.Session.GetString("LoginUserName"); if (string.IsNullOrEmpty(userId)) { if (IsAjaxRequest(context.HttpContext.Request)) { //是ajax请求 context.Result = new JsonResult(new { status = "error", message = "你没有登录" }); } else { var result = new RedirectResult("~/Account/Login"); context.Result = result; } return; } //admin管理员不需要权限检查 if (!string.IsNullOrEmpty(userName) && userName.Equals("admin")) { return; } #endregion #region 获取访问目标对象上的特性 //所有目标对象上所有特性Attribute //var attrs = context.ActionDescriptor.EndpointMetadata.ToList(); //获取所有目标对象上所有特性CheckPermissionAttribute var attrs = context.ActionDescriptor.EndpointMetadata.ToList().Where(r => r as CheckPermissionAttribute != null).ToList(); //获取CheckPermissionAttribute最下面的一个 //var attr = endpoint?.Metadata.GetMetadata<CheckPermissionAttribute>(); //获取过滤器特性 //var pAttr = context.Filters.Where(r => r as VaCantAuthorizationFilter != null).ToList(); #endregion #region 获取当前访问的区域、控制器和action //1. 获取区域、控制器、Action的名称 ////必须在区域里的控制器上加个特性[Area("")]才能获取 //string areaName = context.ActionDescriptor.RouteValues["area"] == null ? "" : context.ActionDescriptor.RouteValues["area"].ToString(); //string controllerName = context.ActionDescriptor.RouteValues["controller"] == null ? "" : context.ActionDescriptor.RouteValues["controller"].ToString(); //string actionName = context.ActionDescriptor.RouteValues["action"] == null ? "" : context.ActionDescriptor.RouteValues["action"].ToString(); //获取请求的区域,控制器,action名称 var area = context.RouteData.DataTokens["area"]?.ToString(); var controller = context.RouteData.Values["controller"]?.ToString(); var action = context.RouteData.Values["action"]?.ToString(); #endregion #region 当前登入的非admin用户的权限检查 //获取当前用户对应角色的所有权限 var permissionNames = CacheCommon.GetCacheByPermissionNames(); if (permissionNames != null && permissionNames.Count > 0) { foreach (var item in attrs) { if (!permissionNames.Contains(item.ToString())) { if (IsAjaxRequest(context.HttpContext.Request)) { //是ajax请求 context.Result = new JsonResult(new { status = "error", message = "你没有权限" }); } else { var result = new RedirectResult("~/Home/Index"); context.Result = result; } return; } } } else { if (IsAjaxRequest(context.HttpContext.Request)) { //是ajax请求 context.Result = new JsonResult(new { status = "error", message = "你没有任何权限" }); } else { var result = new RedirectResult("~/Home/Index"); context.Result = result; } return; } #endregion }
public override async Task <bool> RemoveAsync(string key, string dataKey) { return(KeyExists(key) ? await _db.HashDeleteAsync(CacheCommon.AddSysCustomKey(sysRedisKey, key), dataKey) : false); }
public override bool Remove(string key) { return(KeyExists(key) ? mc.Delete(CacheCommon.AddSysCustomKey(sysMemCacheKey, key)) : false); }
public override bool KeyExists(string key, string dataKey) { return(_db.HashExists(CacheCommon.AddSysCustomKey(sysRedisKey, key), dataKey)); }
public override bool Remove(string key, string dataKey) { return(KeyExists(key, dataKey) ? _db.HashDelete(CacheCommon.AddSysCustomKey(sysRedisKey, key), dataKey) : false); }
public override bool Set <T>(string key, string dataKey, T value, TimeSpan?expiry = default(TimeSpan?)) { var newValue = CacheCommon.ConvertJson <T>(value); return(_db.HashSet(CacheCommon.AddSysCustomKey(sysRedisKey, key), dataKey, newValue)); }
public override bool KeyExists(string key) { return(mc.KeyExists(CacheCommon.AddSysCustomKey(sysMemCacheKey, key))); }