public IActionResult SetListComplexObject() { List <SampleObject> lstSampleObject = new List <SampleObject>(); if (RedisCacheHelper.GetDatabase() != null) { lstSampleObject.Add(new SampleObject { Country = "Argentina", Id = 1, Name = "Maradona" }); lstSampleObject.Add(new SampleObject { Country = "Portugal", Id = 2, Name = "Ronaldo" }); lstSampleObject.Add(new SampleObject { Country = "Puskas", Id = 3, Name = "Hungary" }); RedisCacheHelper.Set("test2", lstSampleObject); } return(RedirectToActionPermanent("Index")); }
public IActionResult GetListComplexObject() { List <SampleObject> lstSampleObject = new List <SampleObject>(); if (RedisCacheHelper.GetDatabase() != null) { lstSampleObject = RedisCacheHelper.Get <List <SampleObject> >("test2"); } return(View(lstSampleObject)); }
public IActionResult GetSimpleComplexObject() { SampleObject sampleObject = new SampleObject(); if (RedisCacheHelper.GetDatabase() != null) { sampleObject = RedisCacheHelper.Get <SampleObject>("test1"); } return(View(sampleObject)); }
public IActionResult Index() { if (RedisCacheHelper.GetDatabase() != null) { return(View(true)); } else { return(View(false)); } }
public IActionResult SetSimpleComplexObject() { if (RedisCacheHelper.GetDatabase() != null) { SampleObject sampleObject = new SampleObject { Country = "Brazil", Id = 7, Name = "Mané" }; RedisCacheHelper.Set("test1", sampleObject); } return(RedirectToActionPermanent("Index")); }
private dynamic Autherize(HttpContext context) { dynamic resp = new ExpandoObject(), response = new ExpandoObject(); resp.IsValid = false; try { string sessionID = context.Request?.Headers["Authorization"]; if ((sessionID == null) || (!sessionID.Contains("Bearer "))) { resp.Message = "Missing session info in Header/Please validate format 'Bearer<Space><SessionId>'"; resp.StatusCode = 401; LogManager.Log(resp.Message, LogType.Error); } else { sessionID = sessionID.Split(" ")[1]; if (RedisCacheHelper.GetDatabase() != null) { dynamic Rc = RedisCacheHelper.Get(sessionID); if (Rc == null) { response = UserFacade.ValidateSession(sessionID); if ((!response.Success) || (response.Data.GetType() != typeof(Newtonsoft.Json.Linq.JObject)) || (!(bool)response.Data.isValid)) { resp.Message = "Invalid Session"; resp.StatusCode = 401; LogManager.Log("Invalid Session sessionID " + sessionID, LogType.Error); } else { RedisCacheHelper.Set(sessionID, response.Data); resp.IsValid = true; resp.UserInfo = response.Data; } } else { resp.IsValid = true; resp.UserInfo = Rc; } } else { resp.Message = "Internal Server Error"; resp.StatusCode = 500; LogManager.Log("Redis Connection Failure ", LogType.Error); } } } catch (Exception ex) { resp.IsValid = false; resp.Message = ex.Message; resp.StatusCode = 500; LogManager.Log(ex, LogType.Error); } context.Request.Headers.Add("SessionData", (string)CommonUtils.JsonSerialize(resp)); return(context); }