Exemple #1
0
        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"));
        }
Exemple #2
0
        public IActionResult GetListComplexObject()
        {
            List <SampleObject> lstSampleObject = new List <SampleObject>();

            if (RedisCacheHelper.GetDatabase() != null)
            {
                lstSampleObject = RedisCacheHelper.Get <List <SampleObject> >("test2");
            }
            return(View(lstSampleObject));
        }
Exemple #3
0
        public IActionResult GetSimpleComplexObject()
        {
            SampleObject sampleObject = new SampleObject();

            if (RedisCacheHelper.GetDatabase() != null)
            {
                sampleObject = RedisCacheHelper.Get <SampleObject>("test1");
            }
            return(View(sampleObject));
        }
Exemple #4
0
 public IActionResult Index()
 {
     if (RedisCacheHelper.GetDatabase() != null)
     {
         return(View(true));
     }
     else
     {
         return(View(false));
     }
 }
Exemple #5
0
 public IActionResult SetSimpleComplexObject()
 {
     if (RedisCacheHelper.GetDatabase() != null)
     {
         SampleObject sampleObject = new SampleObject
         {
             Country = "Brazil",
             Id      = 7,
             Name    = "Mané"
         };
         RedisCacheHelper.Set("test1", sampleObject);
     }
     return(RedirectToActionPermanent("Index"));
 }
Exemple #6
0
        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);
        }