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

AppendCookie() public method

public AppendCookie ( Cookie cookie ) : void
cookie Cookie
return void
        public void AppendCookie(Cookie cookie)
        {
            if (cookie == null)
            {
                throw new ArgumentNullException(nameof(cookie));
            }
            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"cookie: {cookie}");
            Cookies.Add(cookie);
        }

Usage Example

		/// <summary>
		/// Automatically sends the appropriate response to the user agent.
		/// </summary>
		/// <param name="response">The response to set to this message.</param>
		public virtual void Send(HttpListenerResponse response) {
			Requires.NotNull(response, "response");

			response.StatusCode = (int)this.Status;
			MessagingUtilities.ApplyHeadersToResponse(this.Headers, response);
			foreach (HttpCookie httpCookie in this.Cookies) {
				var cookie = new Cookie(httpCookie.Name, httpCookie.Value) {
					Expires = httpCookie.Expires,
					Path = httpCookie.Path,
					HttpOnly = httpCookie.HttpOnly,
					Secure = httpCookie.Secure,
					Domain = httpCookie.Domain,
				};
				response.AppendCookie(cookie);
			}

			if (this.ResponseStream != null) {
				response.ContentLength64 = this.ResponseStream.Length;
				this.ResponseStream.CopyTo(response.OutputStream);
			}

			response.OutputStream.Close();
		}
All Usage Examples Of System.Net.HttpListenerResponse::AppendCookie