This is Microsoft.Owin Source Code.
internal static IDictionary<string, string> GetCookies(IOwinRequest request) { var cookies = request.Get<IDictionary<string, string>>("Microsoft.Owin.Cookies#dictionary"); if (cookies == null) { cookies = new Dictionary<string, string>(StringComparer.Ordinal); request.Set("Microsoft.Owin.Cookies#dictionary", cookies); } string text = GetHeader(request.Headers, "Cookie"); if (request.Get<string>("Microsoft.Owin.Cookies#text") != text) { cookies.Clear(); ParseDelimited(text, SemicolonAndComma, AddCookieCallback, cookies); request.Set("Microsoft.Owin.Cookies#text", text); } return cookies; }
This is owin Define
Required | Key Name | Value Description |
---|---|---|
Yes | owin.RequestBody | A Streamwith the request body, if any. Stream.NullMAY be used as a placeholder if there is no request body. See Request Body. |
Yes | owin.RequestHeaders | An IDictionary<string, string[]>of request headers. See Headers. |
Yes | owin.RequestMethod | A stringcontaining the HTTP request method of the request (e.g., "GET", "POST"). |
Yes | owin.RequestPath | A stringcontaining the request path. The path MUST be relative to the "root" of the application delegate. See Paths. |
Yes | owin.RequestPathBase | A stringcontaining the portion of the request path corresponding to the "root" of the application delegate; see Paths. |
Yes | owin.RequestProtocol | A stringcontaining the protocol name and version (e.g. "HTTP/1.0"or "HTTP/1.1"). |
Yes | owin.RequestQueryString | A stringcontaining the query string component of the HTTP request URI, without the leading "?" (e.g., "foo=bar&baz=quux"). The value may be an empty string. |
Yes | owin.RequestScheme | A stringcontaining the URI scheme used for the request (e.g., "http", "https"); see URI Scheme. |
No | owin.RequestId | An optional stringthat uniquely identifies a request. The value is opaque and SHOULD have some level of uniqueness. A Host MAY specify this value. If it is not specified, middleware MAY set it. Once set, it SHOULD NOT be modified. |
No | owin.RequestUser | An optional identity that represents the user associated with a request. The identity MUST be a ClaimsPrincipal. Middleware MAY specify this value. If it is not specified, middleware MAY set it. Once set, it MAY BE modified. |
There has nothing about Environment["Microsoft.Owin.Cookies#dictionary"] or Environment["Microsoft.Owin.Cookies#text"]
How to get cookies in pure owin?like this?or other ways?maybe Mircorosoft need add owin.Request.Cookies at next version.
public CookieCollection(IDictionary<string, string[]> headers) { if (headers.ContainsKey("Cookie")) { string[] tempArray = headers["Cookie"][0].Split('&', '='); if ((tempArray.Length & 1) == 0) { int len = tempArray.Length >> 1; int i = 0; while (i < len) { cookie.Add(tempArray[i << 1],Uri.UnescapeDataString(tempArray[(i << 1) + 1])); } } } }