Share via


HttpResponseHeadersExtensions.AddCookies Method

Adds cookies to a response. Each Set-Cookie header is represented as one CookieHeaderValue instance. A CookieHeaderValue contains information about the domain, path, and other cookie information as well as one or more CookieState instances. Each CookieState instance contains a cookie name and whatever cookie state is associate with that name. The state is in the form of a NameValueCollection which on the wire is encoded as HTML Form URL-encoded data. This representation allows for multiple related "cookies" to be carried within the same Cookie header while still providing separation between each cookie state. A sample Cookie header is shown below. In this example, there are two CookieState with names state1 and state2 respectively. Further, each cookie state contains two name/value pairs (name1/value1 and name2/value2) and (name3/value3 and name4/value4). <code> Set-Cookie: state1:name1=value1&amp;name2=value2; state2:name3=value3&amp;name4=value4; domain=domain1; path=path1; </code>

Namespace:  System.Net.Http
Assembly:  System.Net.Http.Formatting (in System.Net.Http.Formatting.dll)

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Sub AddCookies ( _
    headers As HttpResponseHeaders, _
    cookies As IEnumerable(Of CookieHeaderValue) _
)
'Usage
Dim headers As HttpResponseHeaders 
Dim cookies As IEnumerable(Of CookieHeaderValue)

headers.AddCookies(cookies)
public static void AddCookies(
    this HttpResponseHeaders headers,
    IEnumerable<CookieHeaderValue> cookies
)
[ExtensionAttribute]
public:
static void AddCookies(
    HttpResponseHeaders^ headers, 
    IEnumerable<CookieHeaderValue^>^ cookies
)
static member AddCookies : 
        headers:HttpResponseHeaders * 
        cookies:IEnumerable<CookieHeaderValue> -> unit
public static function AddCookies(
    headers : HttpResponseHeaders, 
    cookies : IEnumerable<CookieHeaderValue>
)

Parameters

  • headers
    Type: HttpResponseHeaders

    The response headers

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type HttpResponseHeaders. When you use instance method syntax to call this method, omit the first parameter. For more information, see https://msdn.microsoft.com/en-us/library/bb384936(v=vs.108) or https://msdn.microsoft.com/en-us/library/bb383977(v=vs.108).

See Also

Reference

HttpResponseHeadersExtensions Class

System.Net.Http Namespace