Last post May 14, 2018 04:51 PM by omortis
May 11, 2018 02:34 PM|omortis|LINK
This question pertains to 4.6.1 in VS2017.
I am following the docs here for getting cookie data from a request:
I have been working with the HttpRequestMessage for a while, no problem. However, in the sample code above:
request: type HttpRequestMessage
request.Headers: type HttpRequestHeaders
According to the class docs:
This type does not have a GetCookies() method, however VS2017 shows one to be available. Using that method with:
var cookie = message.Headers.GetCookies();
cookies.GetType() returns: System.Collections.ObjectModel.Collection`1[System.Net.Http.Headers.CookieHeaderValue] (`1 wha???)
cookies.GetType() returns: System.Net.Http.Headers.CookieHeaderValue
That type also does not exist in the class docs for HttpHeaders.
Accessing cookies.ToString() gives me a string with all the cookie values in it as a semi-colon delimited string.
Are we supposed to parse this string to obtain cookie key/value pairs? I don't mind doing that but it seems odd and very 1998- am I missing something here? How are we supposed to parse cookies in an HttpRequestMessage in 4.6.1?
Edit: reading a little further is seems CookieHeaderValue is part of .NET Core??
May 14, 2018 06:01 AM|Yohann Lu|LINK
The cookie issued from the client side is retrieved using the GetCookies() method of the Headers collection. The cookie is returned as
CookieHeaderValue. The value of the cookie can then be read using the Value
The HttpRequestHeadersExtensions may helpful for you.
Note: Please Obtain a specific Cookie value based on the content of the
How To Set Cookies in ASP.Net Web API:
If you have a specific issue, Please include all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages or you can upload your demo that
We can download it and debugging. This will help us quickly analyze your problem.
May 14, 2018 04:51 PM|omortis|LINK
Yong Lu - thanks for the information, I am working my way through it. For the second time in 2 weeks I started adding System.Net.* references to a solution that uses System.Web.* and ended up with a project that would compile but not run. Backtracking, and
Edit: I moved from Message Handlers to some simple OwinMiddleware and it fit my project better. Working with IOwinContext in an Owin hosted stack is much cleaner.