Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cookies in ASP.NET Core rc2

Can someone pls explain how to store and get cookies in an ASP.NET Core rc2 application? I can only find outdated information about the old HttpContext.Response.Cookies.Get and Add methods, neither of which still exist in Core. Also, the HttpCookie class doesn't seem to exist either.

What is the new cookie class and how can I get and add one?

(Note: I am not specifically taking about authentication cookies, just general data cookies)

like image 802
hholtij Avatar asked Dec 18 '22 16:12

hholtij


1 Answers

For getting request cookie value:

HttpContext.Request.Cookies["<key>"]

Setting response cookie:

HttpContext.Response.Cookies.Append("<key>", <value>, <options?>)
like image 65
adem caglin Avatar answered Jan 18 '23 06:01

adem caglin