//身份验证 protected override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); bool isLogin = false; //判断Cookie中是否有对应数据 if (Request.Cookies["LData"] != null) { //有 string key = Request.Cookies["LData"].Value; object obj = MemcacheHelper.Get(key); if (obj != null) { //反序列化 UserLogin = SerializeHelper.DeserializeToObject <UserLoginViewModel>(obj.ToString()) as UserLoginViewModel; } if (UserLogin != null) { //登录信息正确 isLogin = true; } } if (!isLogin) { //未登录跳转到登录界面 filterContext.Result = Redirect(Url.Action("Index", "Login")); } }
/// <summary> /// 获取配置文件内容比反序列化为T(永不过期) /// </summary> /// <param name="configFilePath">配置文件路径</param> /// <returns>配置对象</returns> public static T GetConfig <T>(string configFilePath) where T : class { var cacheKey = string.Concat(configFilePath, typeof(T).FullName, HttpContext.Current == null ? AppDomain.CurrentDomain.BaseDirectory.ToMD5String() : HttpContext.Current.Request.Url.Host); return(MemcacheHelper.Get(() => { T config; lock (GetLockObject(configFilePath)) { if (!Path.IsPathRooted(configFilePath)) { configFilePath = GetMapPath(configFilePath); } try { var xmlSerializer = new XmlSerializer(typeof(T)); using (var streamReader = new StreamReader(configFilePath)) { config = xmlSerializer.Deserialize(streamReader) as T; } } catch //(InvalidOperationException exception) { return null; } } return config; }, cacheKey, false)); }
public JsonResult ResetPassword(string active, ResetPwd resetPwd) { var data = new { code = 1, msg = "修改失败" }; if (!string.IsNullOrEmpty(active) && ModelState.IsValid) { if (TempData[Keys.ValidCode] == null || !TempData[Keys.ValidCode].ToString().Equals(resetPwd.Code, StringComparison.CurrentCultureIgnoreCase)) { data = new { code = 1, msg = "验证码错误" }; //Session[Keys.ValidCode] = null; return(Json(data)); } var obj = MemcacheHelper.Get(active); if (obj != null) { var user = SerializerHelper.DeserializeToObject <User>(obj.ToString()); if (user != null) { user.Login_Password = resetPwd.Password.Md5_32(); userService.EditEntity(user); if (userService.SaveChanges()) { data = new { code = 0, msg = "修改成功,请牢记新密码。" }; MemcacheHelper.Set(active, null, DateTime.Now.AddHours(-1)); } } } } return(Json(data)); }
public RespondWebViewData <RespondOnlineSigninUserViewModel> GetOnlineSigninUserByUserID_g(RequestOnlineSigninUserViewModel request) { return(MemcacheHelper.Get(() => { var parameter = new OnlineSigninUserParameter { SGuid = request.SGuid, UserIP = request.AddressIP }; var dataModel = this.mSiginUserDataAccess.GetOnlineSigninUserByUserID_g(parameter); if (dataModel == null) { return new RespondWebViewData <RespondOnlineSigninUserViewModel>(WebViewErrorCode.LoginRequired); } return new RespondWebViewData <RespondOnlineSigninUserViewModel> { rows = new RespondOnlineSigninUserViewModel { UserID = dataModel.userid, LoginName = dataModel.username, SGuid = dataModel.sguid, ExpTime = dataModel.exptime, UserIP = dataModel.userip } }; }, string.Format(preCacheKey, "GetOnlineSigninUserByUserID_g"), DateTime.Now.AddMinutes(WebConfigHelper.MemCachedExpTime()), false, request.SGuid, request.AddressIP)); }
public List <RespondHeadButtonsViewModel> QueryHeadButtonsViewModelsByMenuID(RequestHeadButtonsViewModel request) { //TODO 配置每个单据的按钮权限后需清除缓存 return(MemcacheHelper.Get(new RequestMemcacheParameter <List <RespondHeadButtonsViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "QueryHeadButtonsViewModelsByMenuID"), #region ==================================== CallBackFunc = () => { var parameter = new HeadButtonsParameter { MenuID = request.MenuID, UserId = this.mSigninUser.UserID }; var dataModels = this.mHeadButtonsDataAccess.QueryHeadButtonsViewModelsByMenuID(parameter); var viewModels = dataModels.Select(model => new RespondHeadButtonsViewModel { ButtonDisabled = model.ButtonDisabled, ButtonIconCls = model.ButtonIconCls, ButtonName = model.ButtonName, ButtonText = model.ButtonText }).ToList(); return viewModels; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(WebConfigHelper.MemCachedExpTime()), ManageCacheKeyForKey = THISSERVICE_PRE_CACHE_KEY_MANAGE, ParamsKeys = new object[] { request.MenuID, this.mSigninUser.UserID } })); }
public List <RespondGetAllEmployeeViewModel> GetAllEmployee(RequestWebViewData <RequestGetAllEnityDataViewModel> request) { return(MemcacheHelper.Get(new RequestMemcacheParameter <List <RespondGetAllEmployeeViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "GetAllEmployee"), #region ===================== CallBackFunc = () => { var parameter = new QueryEmployeeListParameter { SerialNumber = request.data.Keywords }; var dataList = this.mEmployeeDataAccess.GetAllEmployee(parameter); var respond = dataList.Select(item => new RespondGetAllEmployeeViewModel { EmpId = item.empid, SerialNumber = item.serialnumber, Name = item.name, Comment = item.comment, Spelling = item.pinyin }).ToList(); return respond; }, #endregion ManageCacheKeyForKey = ServiceMemcachedKeyManageConst.CommonAjax, ExpiresAt = DateTime.Now.AddMinutes(30), ParamsKeys = new object[] { request.data.Keywords, this.mSigninUser.UserID } })); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); //if (Session["userInfo"] == null) //{ // filterContext.HttpContext.Response.Redirect("/Login/Index"); //} bool isScuess = false; if (Request.Cookies["sessionID"] != null) { string sessionID = Request.Cookies["sessionID"].Value; object obj = MemcacheHelper.Get(sessionID); if (obj != null) { UserInfo userInfo = SerializeHelper.DeserializeToObject <UserInfo>(obj.ToString()); LoginUser = userInfo; //模拟滑动过期时间 MemcacheHelper.Set(sessionID, obj, DateTime.Now.AddMinutes(20)); isScuess = true; } } if (!isScuess) { filterContext.Result = Redirect("/Login/Index"); } }
public RespondWebViewData <RespondQueryEmployeeViewModel> GetEmployeeByEmpId(RequestWebViewData <RequestGetEmployeeByIdViewModel> request) { return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <RespondQueryEmployeeViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "GetEmployeeByEmpId"), #region ==================== CallBackFunc = () => { var respond = new RespondWebViewData <RespondQueryEmployeeViewModel> { rows = new RespondQueryEmployeeViewModel() }; var employee = this.mEmployeeDataAccess.GetemployeeDataModelById(request.data.EmpId); if (employee == null) { return respond; } if (employee.deleted == (short)CommonDeleted.Deleted || employee.status != (short)CommonStatus.Used) { return respond; } var totalScale = this.mSystemParameterConfigViewService.SystemParameterConfig()[SystemParameterConfigConst.TotalScale].ParameterConfigValue.ToInt16(); respond = new RespondWebViewData <RespondQueryEmployeeViewModel> { rows = new RespondQueryEmployeeViewModel { Address = employee.address, ChildNumber = employee.childnumber, ClassId = employee.classid, Comment = employee.comment, Deleted = employee.deleted, DepId = employee.depid, DepName = employee.depname, EmpId = employee.empid, LowestDiscount = employee.lowestdiscount, Mobile = employee.mobile, Name = employee.name, ParentId = employee.parentid, PreInAdvanceTotal = employee.preinadvancetotal.ToNumberString(totalScale), PrePayFeeTotal = employee.prepayfeetotal.ToNumberString(totalScale), SerialNumber = employee.serialnumber, Status = employee.status, Spelling = employee.pinyin, Sort = employee.sort } }; return respond; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(30), ManageCacheKeyForKey = ServiceMemcachedKeyManageConst.BasicEmployee, ParamsKeys = new object[] { request.data.EmpId } })); }
public RespondWebViewData <List <RespondSystemParameterConfigViewModel> > GetSystemParameterConfigViewModels() { return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <List <RespondSystemParameterConfigViewModel> > > { CacheKey = string.Format(PRE_CACHE_KEY, "GetSystemParameterConfigViewModels"), #region ======================== CallBackFunc = () => { var dataModels = this.mSystemParameterConfigDataAccess.GetSystemParameterConfigDataModels(); var viewModels = new RespondWebViewData <List <RespondSystemParameterConfigViewModel> > { rows = dataModels.Select(data => new RespondSystemParameterConfigViewModel { ParameterConfigName = data.ParameterConfigName, ParameterConfigValue = data.ParameterConfigValue }).ToList() }; return viewModels; }, #endregion ManageCacheKeyForKey = THISSERVICE_PRE_CACHE_KEY_MANAGE, ParamsKeys = new object[] { this.mSigninUser.UserID, this.mSigninUser.CompanySerialNum } })); }
public RespondWebViewData <RespondSystemParameterConfigViewModel> GetSystemParameterConfigViewModel(RequestWebViewData <RequestSystemParameterConfigViewModel> request) { return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <RespondSystemParameterConfigViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "GetSystemParameterConfigViewModel"), #region =================================================== CallBackFunc = () => { var kvConfig = this.BuildDictionay(); var value = kvConfig[request.data.ParameterConfigName]; return new RespondWebViewData <RespondSystemParameterConfigViewModel> { rows = value }; }, #endregion ManageCacheKeyForKey = THISSERVICE_PRE_CACHE_KEY_MANAGE, ParamsKeys = new object[] { request.data.ParameterConfigName, this.mSigninUser.CompanySerialNum } })); }
public RespondWebViewData <RespondQueryClientViewModel> GetClientByClientId(RequestWebViewData <RequestGetClientByIdViewModel> request) { return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <RespondQueryClientViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "GetClientByClientId"), #region ==================== CallBackFunc = () => { var respond = new RespondWebViewData <RespondQueryClientViewModel> { rows = new RespondQueryClientViewModel() }; var client = this.mClientDataAccess.GetclientDataModelById(request.data.ClientId); if (client == null) { return respond; } if (client.deleted == (short)CommonDeleted.Deleted || client.status != (short)CommonStatus.Used) { return respond; } respond = new RespondWebViewData <RespondQueryClientViewModel> { rows = new RespondQueryClientViewModel { Address = client.address, Alias = client.alias, ChildNumber = client.childnumber, ClassId = client.classid, ClientId = client.clientid, Comment = client.comment, Credits = client.credits.ToNumberString(5), LinkAddress = client.linkaddress, LinkMan = client.linkman, LinkTel = client.linktel, Name = client.name, ParentId = client.parentid, Spelling = client.pinyin, PriceMode = client.pricemode, SerialNumber = client.serialnumber, Sort = client.sort, ZipCode = client.zipcode } }; return respond; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(30), ManageCacheKeyForKey = ServiceMemcachedKeyManageConst.BasicClient, ParamsKeys = new object[] { request.data.ClientId } })); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { HttpCookie httpCookie = Request.Cookies.Get("userInfoSID"); bool idIsPass = false; UserInfo userInfo = null; //账号验证 begin if (httpCookie != null) { string userInfoSID = httpCookie.Value; object obj = MemcacheHelper.Get(userInfoSID); if (obj != null) { userInfo = SerializeHelper.DeserializeToObject <UserInfo>(obj.ToString()); ////查看该用户有没有角色、并获取角色。 //roleInfo = UserInfoService.LoadEntities(u => u.ID == userInfo.ID && u.UPwd == userInfo.UPwd).FirstOrDefault().RoleInfo.FirstOrDefault(); if (userInfo != null) { idIsPass = true; } } } // //账号验证 end if (idIsPass) //账号验证通过。 { string url = Request.Url.AbsolutePath.ToLower(); string method = Request.HttpMethod; string controllerName = RouteData.Values["controller"].ToString().ToLower(); var query = UserInfoService.LoadEntities(u => u.ID == userInfo.ID && u.UPwd == userInfo.UPwd).FirstOrDefault().RoleInfo; int count = (from u in query from a in u.ActionInfo where /*a.HttpMethod == method&&*/ a.ControllerName == controllerName //a.Url == url select a).Count(); if (count > 0) { return; } else { filterContext.Result = Redirect(@"/static/Error/nopermission.html"); return; } } else //账号验证未通过。 { filterContext.Result = Redirect("/Login/Index"); return; } // base.OnActionExecuting(filterContext); //filterContext.Result = Redirect("/Login/Index"); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); string strController = filterContext.RouteData.Values["controller"].ToString(); string strAction = filterContext.RouteData.Values["action"].ToString(); if (strController.Equals("Login") || strController.Equals("Error")) { return; // 如果访问的是 Login 就直接放回 } // 校验用户登录 if (filterContext.HttpContext.Request.Cookies["LoginID"] == null) { filterContext.HttpContext.Response.Redirect("/Login/Index"); return; } string loginId = filterContext.HttpContext.Request.Cookies["LoginID"].Value; if (string.IsNullOrEmpty(loginId)) { // 留一个后门,请求的 Contorller 是Articles 或 Search ,则忽略登录验证 if (strController.Equals("Articles") || strController.Equals("Search")) { return; } filterContext.HttpContext.Response.Redirect("/Login/Index"); return; } object loginUser = MemcacheHelper.Get(loginId); //SerializeHelper if (loginUser == null) { filterContext.HttpContext.Response.Redirect("/Login/Index"); return; } UserInfo userInfo = SerializeHelper.DeserializeToObject <UserInfo>(loginUser.ToString()); if (userInfo == null) { filterContext.HttpContext.Response.Redirect("/Login/Index"); return; } MemcacheHelper.Set(loginId, SerializeHelper.SerializeToString(userInfo), DateTime.Now.AddMinutes(20)); // 重新设置过期时间 即 平滑时间 // 校验用户权限 IApplicationContext ctx = ContextRegistry.GetContext(); IUserInfoService userInfoService = ctx.GetObject <UserInfoService>("UserInfoService"); IActionInfoService actionInfoService = ctx.GetObject <ActionInfoService>("ActionInfoService"); userInfo = userInfoService.LoadEntites(o => o.ID.Equals(userInfo.ID)).FirstOrDefault(); BaseController.LoginUser = userInfo; if (!actionInfoService.ValidateUserAction(userInfo, filterContext.HttpContext.Request)) { filterContext.HttpContext.Response.Redirect("/Error/Index/?msg=" + "无访问权限"); } }
public string GetStringValue(string key) { var value = MemcacheHelper.Get(key)?.ToString(); if (value == null) { value = settingRepository.LoadEntity(s => s.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase))?.Value; MemcacheHelper.Set(key, value, DateTime.Now.AddHours(1)); } return(value); }
public RespondWebViewData <RespondQueryStorageViewModel> GetStorageByStorageId(RequestWebViewData <RequestGetStorageByIdViewModel> request) { return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <RespondQueryStorageViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "GetStorageByStorageId"), #region ==================== CallBackFunc = () => { var respond = new RespondWebViewData <RespondQueryStorageViewModel> { rows = new RespondQueryStorageViewModel() }; var storage = this.mStorageDataAccess.GetstorageDataModelById(request.data.StorageId); if (storage == null) { return respond; } if (storage.deleted == (short)CommonDeleted.Deleted || storage.status != (short)CommonStatus.Used) { return respond; } respond = new RespondWebViewData <RespondQueryStorageViewModel> { rows = new RespondQueryStorageViewModel { Alias = storage.alias, ParentId = storage.parentid, Spelling = storage.PinYin, ChildNumber = storage.childnumber, ClassId = storage.classid, Comment = storage.comment, Deleted = storage.deleted, Name = storage.name, SerialNumber = storage.serialnumber, Sort = storage.sort, StorageId = storage.stoid, Status = storage.status } }; return respond; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(30), ManageCacheKeyForKey = ServiceMemcachedKeyManageConst.BasicStorage, ParamsKeys = new object[] { request.data.StorageId } })); }
public tb_App_UserEntity GetModelByCache(string openid) { string key = "appuser" + openid; tb_App_UserEntity model = null; object obj = MemcacheHelper.Get(key); if (obj != null) { model = Jnwf.Utils.Json.JsonHelper.DeserializeJson <tb_App_UserEntity>(obj.ToString()); } return(model); }
public RespondWebViewData <List <RespondQueryUserViewModel> > GetUserList(RequestWebViewData <RequestQueryUserViewModel> request) { return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <List <RespondQueryUserViewModel> > > { CacheKey = string.Format(PRE_CACHE_KEY, "GetUserList"), #region ============================================ CallBackFunc = () => { var parameter = new QueryUserParameter { EmpId = request.data.EmpId, PageIndex = request.page, PageSize = request.rows, UserName = request.data.UserName }; var pageList = this.mUserDataAccess.GetUserPageData(parameter); var respond = new RespondWebViewData <List <RespondQueryUserViewModel> > { total = pageList.DataCount, rows = pageList.Datas.Select(item => new RespondQueryUserViewModel { CTime = item.CTime, Comment = item.Comment, EmpId = item.EmpId, Manager = item.Manager, Prefix = item.Prefix, Status = item.Status, UserName = item.UserName, UsePwd = item.UsePwd, UserId = item.UserId, Deleted = item.Deleted, Synchron = item.Synchron, ComId = item.ComId }).ToList() }; return respond; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(30), ManageCacheKeyForKey = ServiceMemcachedKeyManageConst.UserManage, ParamsKeys = new object[] { request.data.EmpId, request.page, request.rows, request.data.UserName } })); }
public RespondCompanyInfoViewModel GetCompanyInfoViewModel(RequestCompanyInfoViewModel request) { var respond = MemcacheHelper.Get(() => { var filePath = BuildConnectionFilePath.BuildFilePath(request.CompanyID); var _respond = new RespondCompanyInfoViewModel(); if (ExistsFileHelper.ExistsFile(filePath)) { var connectionConfig = ConfigHelper.GetConfig <DbConnectionConfig>(filePath); _respond = new RespondCompanyInfoViewModel { CompanyID = request.CompanyID, ConnectTimeout = connectionConfig.ConnectTimeout, Database = connectionConfig.Database, Password = connectionConfig.Password, Server = connectionConfig.Server, UserID = connectionConfig.UserID }; return(_respond); } var parameter = new CompanyInfoParameter { CompanyID = request.CompanyID }; var dataModel = this.mCompanyInfoDataAccess.GetCompanyInfoDataModelByID(parameter); if (dataModel == null) { return(_respond); } _respond = new RespondCompanyInfoViewModel { CompanyID = dataModel.comid, ConnectTimeout = dataModel.timeout, Database = dataModel.dbase, Password = dataModel.pwd, Server = dataModel.dbserver, UserID = dataModel.uid }; var _DbconnectionConfig = new DbConnectionConfig { ConnectTimeout = dataModel.timeout, Database = dataModel.dbase, Password = dataModel.pwd, Server = dataModel.dbserver, UserID = dataModel.uid }; ConfigHelper.Save(_DbconnectionConfig, filePath); return(_respond); }, string.Format(preCachedKey, "GetCompanyInfoViewModel"), false, request.CompanyID); return(respond); }
public RespondWebViewData <RespondQueryDepartmentViewModel> GetDepartmentByDepId(RequestWebViewData <RequestGetDepartmentByIdViewModel> request) { return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <RespondQueryDepartmentViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "GetDepartmentByDepId"), #region ==================== CallBackFunc = () => { var respond = new RespondWebViewData <RespondQueryDepartmentViewModel> { rows = new RespondQueryDepartmentViewModel() }; var department = this.mDepartmentDataAccess.GetdepartmentDataModelById(request.data.DepId); if (department == null) { return respond; } if (department.deleted == (short)CommonDeleted.Deleted || department.status != (short)CommonStatus.Used) { return respond; } respond = new RespondWebViewData <RespondQueryDepartmentViewModel> { rows = new RespondQueryDepartmentViewModel { ChildCount = department.childcount, ChildNumber = department.childnumber, ClassId = department.classid, Comment = department.comment, Deleted = department.deleted, DepId = department.depid, Name = department.name, ParentId = department.parentid, SerialNumber = department.serialnumber, Status = department.status, Spelling = department.pinyin, Sort = department.sort.ToString() } }; return respond; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(30), ManageCacheKeyForKey = ServiceMemcachedKeyManageConst.BasicDepartment, ParamsKeys = new object[] { request.data.DepId } })); }
public RespondWebViewData <RespondQuerySubCompanyViewModel> GetSubCompanyByComId(RequestWebViewData <RequestGetSubCompanyByIdViewModel> request) { return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <RespondQuerySubCompanyViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "GetSubCompanyByComId"), #region ================= CallBackFunc = () => { var respond = new RespondWebViewData <RespondQuerySubCompanyViewModel>(WebViewErrorCode.NotExistsDataInfo) { rows = new RespondQuerySubCompanyViewModel() }; var subCompany = this.mSubCompanyDataAccess.GetsubcompanyDataModelById(request.data.ComId); if (subCompany == null) { return respond; } if (subCompany.deleted == (short)CommonDeleted.Deleted || subCompany.status != (short)CommonStatus.Used) { return respond; } respond = new RespondWebViewData <RespondQuerySubCompanyViewModel> { rows = new RespondQuerySubCompanyViewModel { ComId = subCompany.subcomid, Comment = subCompany.comment, Email = subCompany.email, LinkMan = subCompany.linkman, LinkTel = subCompany.linktel, Name = subCompany.name, PriceMode = subCompany.pricemode.ToString(), SerialNumber = subCompany.serialnumber, sort = subCompany.sort.ToString(), Spelling = subCompany.pinyin } }; return respond; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(30), ManageCacheKeyForKey = ServiceMemcachedKeyManageConst.BasicSubCompany, ParamsKeys = new object[] { request.data.ComId } })); }
//Mencache缓存测试 public ActionResult Index() { var obj = MemcacheHelper.Get("zhangyi"); if (obj == null) { MemcacheHelper.Set("zhangyi", "我的名字叫张毅"); } return(View()); }
public RespondWebViewData <List <RespondQueryUnitViewModel> > GetQueryUnitList(RequestWebViewData <RequestQueryUnitViewModel> request) { if (request.data == null) { request.data = new RequestQueryUnitViewModel(); } return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <List <RespondQueryUnitViewModel> > > { CacheKey = string.Format(PRE_CACHE_KEY, "GetQueryUnitList"), #region ================= CallBackFunc = () => { var parameter = new QueryUnitListParameter { Deleted = request.data.Deleted, Name = request.data.Name, PageIndex = request.page, PageSize = request.rows, Status = request.data.Status }; var pageDataList = this.mUnitDataAccess.GetQueryUnitList(parameter); var respond = new RespondWebViewData <List <RespondQueryUnitViewModel> > { total = pageDataList.DataCount, rows = pageDataList.Datas.Select(item => new RespondQueryUnitViewModel { UnitId = item.unitid, Name = item.name, Deleted = item.deleted, Status = item.status, Sort = item.sort.ToString() }).ToList() }; return respond; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(30), ManageCacheKeyForKey = ServiceMemcachedKeyManageConst.BasicUnit, ParamsKeys = new object[] { request.data.Name, request.data.Status, request.data.Deleted, request.page, request.rows } })); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var request = filterContext.HttpContext.Request; var response = filterContext.HttpContext.Response; // 判断是否跳过登录验证 if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), false)) { return; } if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), false)) { return; } var cookie = request.Cookies[Keys.SessionId]; if (cookie != null) { var sessionid = request.Cookies[Keys.SessionId]?.Value; if (sessionid != null) { var obj = MemcacheHelper.Get(sessionid); if (obj != null) { var account = SerializerHelper.DeserializeToObject <Account>(obj.ToString()); if (account != null) { // 滑动过期时间 cookie.Expires = DateTime.Now.AddHours(1); cookie.HttpOnly = true; response.Cookies.Add(cookie); MemcacheHelper.Set(sessionid, obj, DateTime.Now.AddHours(1)); Account = account; return; } } } } if (request.IsAjaxRequest()) { filterContext.Result = new AjaxUnauthorizedResult(); return; } response.StatusCode = 401; var from = filterContext.HttpContext.Server.UrlEncode(filterContext.HttpContext.Request.Url.ToString()); filterContext.Result = new RedirectResult($"/account/signin?returnUrl={from}"); base.OnActionExecuting(filterContext); }
/// <summary> /// 获取当前登陆人的账户信息 /// </summary> /// <returns>账户信息</returns> protected Account GetCurrentAccount() { if (Request.Cookies[Keys.SessionId] != null) { string sessionId = Request.Cookies[Keys.SessionId].Value;//接收从Cookie中传递过来的Memcache的key if (sessionId != null) { object obj = MemcacheHelper.Get(sessionId);//根据key从Memcache中获取用户的信息 return(obj == null ? null : SerializerHelper.DeserializeToObject <Account>(obj.ToString())); } } Redirect("/account/signin"); return(null); }
public RespondWebViewData <RespondQueryUserViewModel> GetUserDataByUserId(RequestWebViewData <RequestQueryUserViewModel> request) { return(MemcacheHelper.Get(new RequestMemcacheParameter <RespondWebViewData <RespondQueryUserViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "GetUserDataByUserId"), #region ======================================================== CallBackFunc = () => { var parameter = new QueryUserParameter { userid = request.data.UserId }; var dataModel = this.mUserDataAccess.GetUserDataByUserId(parameter); if (dataModel == null) { return new RespondWebViewData <RespondQueryUserViewModel>(WebViewErrorCode.NotExistsDataInfo); } var respond = new RespondWebViewData <RespondQueryUserViewModel> { rows = new RespondQueryUserViewModel { CTime = dataModel.CTime, Comment = dataModel.Comment, EmpId = dataModel.EmpId, Manager = dataModel.Manager, Prefix = dataModel.Prefix, Status = dataModel.Status, UserName = dataModel.UserName, UsePwd = dataModel.UsePwd, UserId = dataModel.UserId, Deleted = dataModel.Deleted, Synchron = dataModel.Synchron, ComId = dataModel.ComId } }; return respond; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(30), ManageCacheKeyForKey = ServiceMemcachedKeyManageConst.UserManage, ParamsKeys = new object[] { request.data.UserId } })); }
public List <Article_Category> GetCategories() { List <Article_Category> categories = null; var obj = MemcacheHelper.Get(Keys.Categories); if (obj != null) { categories = SerializerHelper.DeserializeToObject <List <Article_Category> >(obj.ToString()); } if (categories == null) { categories = categoryRepository.LoadEntities(c => true).OrderBy(c => c.Sort).ToList(); MemcacheHelper.Set(Keys.Categories, SerializerHelper.SerializeToString(categories)); } return(categories); }
public List <FriendLinks> GetFriendLinks() { List <FriendLinks> friendLinks = null; var obj = MemcacheHelper.Get(Keys.FriendLinks); if (obj != null) { friendLinks = SerializerHelper.DeserializeToObject <List <FriendLinks> >(obj.ToString()); } if (friendLinks == null) { friendLinks = friendLinksRepository.LoadEntities(f => true).OrderBy(f => f.Sort)?.ToList(); MemcacheHelper.Set(Keys.FriendLinks, SerializerHelper.SerializeToString(friendLinks), DateTime.Now.AddHours(24)); } return(friendLinks); }
public ActionResult UserLogin(Models.LoginForm from) { string vcodeSID = Request.Cookies["vCodeSID"].Value.ToString(); Response.Cookies.Remove("vCodeSID"); //获取正确验证码 string vode = MemcacheHelper.Get(vcodeSID).ToString(); //根据用户名取得用户信息; int id = 0; if ((from.code == null || from.code == "") || from.code.Trim() != vode) { return(Content("no:验证码错误!")); } Model.UserInfo userInfo = userInfoService.LoadEntities(u => u.UName == from.user).FirstOrDefault(); if (userInfo == null) { if (int.TryParse(from.user, out id)) { userInfo = userInfoService.LoadEntities(u => u.ID == id).FirstOrDefault(); if (userInfo == null) { return(Content("no:用户名错误")); } } } if (from.pwd != userInfo.UPwd) { return(Content("no:密码错误")); } if (from.checkpwd != null) { Response.Cookies["userInfo"].Value = SerializeHelper.SerializeToString(userInfo);//登陆成功将userinfo写入cookies Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(1); } else { Response.Cookies.Remove("userInfo"); } string userInfoSID = MemcacheHelper.Set(SerializeHelper.SerializeToString(userInfo), DateTime.Now.AddMinutes(20)); Response.Cookies["userInfoSID"].Value = userInfoSID; // Response.Cookies["userInfoSID"].Expires = DateTime.Now.AddDays(1); return(Content("ok:登陆成功")); }
public List <RespondPanelViewModel> GetLeftNavMenuDataModels() { var parameter = new LeftNavMenuParameter { UserID = this.mSigninUser.UserID }; //TODO 配置菜单权限是需要清除当前的用户的菜单缓存 return(MemcacheHelper.Get(new RequestMemcacheParameter <List <RespondPanelViewModel> > { CacheKey = string.Format(PRE_CACHE_KEY, "GetLeftNavMenuDataModels"), #region =============================== CallBackFunc = () => { var dataModels = this.mLeftNavMenuDataAccess.GetLeftNavMenuDataModels(parameter); var viewModels = dataModels .Where(dataModel => dataModel.parentid == "000001") .Select(dataModel => new RespondPanelViewModel { IconCls = dataModel.iconcls, Title = dataModel.title, Menus = dataModels .Where(_dataModel => _dataModel.parentid == dataModel.classid) .Select(_dataModel => new RespondMenuViewModel { IconCls = _dataModel.iconcls, Title = _dataModel.title, Url = _dataModel.url, ButtonID = _dataModel.buttonid, MenuID = _dataModel.menuid, ClassID = _dataModel.classid, }) .ToList() }).ToList(); return viewModels; }, #endregion ExpiresAt = DateTime.Now.AddMinutes(30), ManageCacheKeyForKey = THISSERVICE_PRE_CACHE_KEY_MANAGE, ParamsKeys = new object[] { this.mSigninUser.UserID } })); }
public List <Favorites> CurrentUserFavorites(long userId) { List <Favorites> favorites = null; var obj = MemcacheHelper.Get(userId.ToString()); if (obj != null) { favorites = SerializerHelper.DeserializeToObject <List <Favorites> >(obj.ToString()); } else { favorites = favoritesRepository.LoadEntities(f => f.User_Id == userId)?.ToList(); MemcacheHelper.Set(userId.ToString(), SerializerHelper.SerializeToString(favorites), DateTime.Now.AddMinutes(10)); } return(favorites); }