Exemplo n.º 1
0
        public void RemoveCookie()
        {
            string sessionid = HttpContext.Request.Cookies["session_id"];

            CookiesContext cookieContext =
                HttpContext.RequestServices.GetService(typeof(CookiesContext)) as CookiesContext;

            cookieContext.DeleteSession(sessionid);
        }
Exemplo n.º 2
0
        private void SetCookie(int userId)
        {
            var            sessionId = Guid.NewGuid().ToString();
            CookiesContext context   = HttpContext.RequestServices.GetService(typeof(CookiesContext)) as CookiesContext;

            CookieOptions cookieOptions = new CookieOptions
            {
                Expires = new DateTimeOffset(DateTime.Now.AddDays(1))
            };

            HttpContext.Response.Cookies.Append("date_of_creation", DateTime.Now.ToString(), cookieOptions); //set cookie
            HttpContext.Response.Cookies.Append("session_id", sessionId, cookieOptions);                     //set cookie

            context.AddSession(userId, sessionId);
        }
Exemplo n.º 3
0
        public int CheckCookie()
        {
            int    userId;
            string sessionid = HttpContext.Request.Cookies["session_id"];

            if (sessionid != null)
            {
                CookiesContext cookieContext =
                    HttpContext.RequestServices.GetService(typeof(CookiesContext)) as CookiesContext;
                userId = cookieContext.GetSession(sessionid);
            }
            else
            {
                userId = -1;
            }

            return(userId);
        }