System.Net.HttpListenerResponse.SetCookie C# (CSharp) Method

SetCookie() public method

public SetCookie ( Cookie cookie ) : void
cookie Cookie
return void
        public void SetCookie(Cookie cookie)
        {
            if (cookie == null)
            {
                throw new ArgumentNullException(nameof(cookie));
            }
            bool added = false;
            try
            {
                Cookies.Add(cookie);
                added = true;
            }
            catch (CookieException)
            {
                Debug.Assert(!added);
            }

            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"cookie: {cookie}");

            if (!added)
            {
                // cookie already existed and couldn't be replaced
                throw new ArgumentException(SR.net_cookie_exists, nameof(cookie));
            }
        }