Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to get cookies at pure owin?

$
0
0

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

RequiredKey NameValue Description
Yes
owin.RequestBody
Stream
 with the request body, if any. 
Stream.Null
 MAY 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
string
 containing the HTTP request method of the request (e.g., 
"GET"
"POST"
).
Yes
owin.RequestPath
string
 containing the request path. The path MUST be relative to the "root" of the application delegate. See Paths.
Yes
owin.RequestPathBase
string
 containing the portion of the request path corresponding to the "root" of the application delegate; see Paths.
Yes
owin.RequestProtocol
string
 containing the protocol name and version (e.g. 
"HTTP/1.0"
 or 
"HTTP/1.1"
).
Yes
owin.RequestQueryString
string
 containing the query string component of the HTTP request URI, without the leading "?" (e.g., 
"foo=bar&amp;baz=quux"
). The value may be an empty string.
Yes
owin.RequestScheme
string
 containing the URI scheme used for the request (e.g., 
"http"
"https"
); see URI Scheme.
No
owin.RequestId
An optional 
string
 that 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]));
                    }
                }
            }
        }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>