Пример #1
0
        public ActionResult <IEnumerable <string> > Get()
        {
            var option = new CookieOptions();

            option.Expires  = DateTime.Now.AddMinutes(10);
            option.Domain   = Request.Host.Host;
            option.Path     = "/";
            option.HttpOnly = true;
            option.Secure   = true;
            option.SameSite = SameSiteMode.Strict;

            var response = new CustomResponse()
            {
                encryptedToken = "encypted",
                valid          = true
            };

            Response.Cookies.Append("sessionId", "123456", option);
            return(Ok(response));
        }
Пример #2
0
        public HttpResponseMessage Post([FromBody] CustomRequest request)
        {
            var response = new CustomResponse()
            {
                encryptedToken = request.token + "encypted",
                valid          = true
            };
            string jsonRes = JsonConvert.SerializeObject(response);

            var resp = new HttpResponseMessage(HttpStatusCode.OK);
            //create and set cookie in response
            var cookie = new CookieHeaderValue("sessionId", "123456");

            cookie.Expires = DateTimeOffset.Now.AddDays(1);
            cookie.Domain  = Request.Host.Host;
            cookie.Path    = "/";

            //resp.Headers.AddCookies(new CookieHeaderValue[] { cookie });
            resp.Content = new StringContent("[OK]", System.Text.Encoding.UTF8, "text/plain");
            return(resp);
        }