5

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)

hholtij
  • 2,906
  • 6
  • 27
  • 42
  • 2
    Have you tried Append (as per https://github.com/aspnet/HttpAbstractions/blob/3a97a6bdfdcc3787bf4b68cecdf277588de5ee76/src/Microsoft.AspNetCore.Http.Features/IResponseCookies.cs)? – Pawel Jun 22 '16 at 05:25
  • See https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNetCore.Authentication.Cookies/ChunkingCookieManager.cs The class has methods for getting request cookie and setting response cookie – adem caglin Jun 22 '16 at 05:40

1 Answers1

13

For getting request cookie value:

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

Setting response cookie:

HttpContext.Response.Cookies.Append("<key>", <value>, <options?>)
adem caglin
  • 22,700
  • 10
  • 58
  • 78