Ashkan Mobayen Khiabani
Ashkan Mobayen Khiabani

Reputation: 34150

Cookies not read correctly in asp.net core

Browser confirms that both curvlist and guestuser cookies exist. However When I get the guestuser it has the correct value:

string Guest = Request.Cookies["guestuser"]; 

but the cookie curvlist is empty:

enter image description here enter image description here enter image description here

The only difference is that guestuser is created in server side, but curvlist created by javascript. But it has nothing to to with reading the cookies

Upvotes: 0

Views: 554

Answers (2)

Nemi Chand
Nemi Chand

Reputation: 146

CookieManager: ASP.Net Core Abstraction layer on top of HTTP Cookie . ASP.NET Core Wrapper to read and write the cookie. it has fluent apis and ease of use.

https://github.com/nemi-chand/CookieManager

Silent features:

  1. it's interface allows you to play with generic object. You don't have to care about casting or serialization.
  2. :The cookie data is protected with the machine key, using security algorithm. For more about data protection.
  3. There are easy options to configure CookieManager. Just add the CookieManager in Configure Service.
  4. Ease to use :The interfaces allows to ease use of read and write http cookie

Have a look

Upvotes: 0

Ashkan Mobayen Khiabani
Ashkan Mobayen Khiabani

Reputation: 34150

Experimenting different values for the cookie, I found out something that is very stupid (correct me if I'm wrong): Apparently cookie name and value is separated by comma so having commas in the value would lead loss of the rest of the value after comma (in my case starting with comma would lead to empty value). I changed the separator in cookie to $ instead of , and now I'm getting the correct value.

But why Asp.net reads cookies this way? (Note that there was no problem when reading cookies with comma separated values in the javascript .

Upvotes: 1

Related Questions