Exemple #1
0
 private void CopyCookies(WebContext _context)
 {
     foreach (Cookie cookie in _context.Cookies)
     {
         cookie.Path     = "/";
         cookie.HttpOnly = true;
         cookie.Secure   = true;
         cookie.Domain   = HttpUtils.AdaptCookieDomain(cookie.Domain);
         _context.Response.Cookies.Add(cookie);
     }
     _context.Response.Cookies = _context.Request.Cookies;
 }
        private string GetCookieString(Cookie cookie)
        {
            var maxage = -1;

            if (cookie.Expires.ToUniversalTime() > DateTime.Now.ToUniversalTime())
            {
                maxage = (cookie.Expires.ToUniversalTime() - DateTime.Now.ToUniversalTime()).TotalSeconds.ToInt();
            }
            var domain = HttpUtils.AdaptCookieDomain(cookie.Domain);

            var result = string.Format("{0}={1}; Path={2}; Max-Age={3}; Domain={4};", cookie.Name, cookie.Value, cookie.Path, maxage, domain);

            if (cookie.HttpOnly)
            {
                result += "HttpOnly;";
            }
            if (cookie.Secure)
            {
                result += "Secure;";
            }
            return(result);
        }