Cookies in ASP.NET Core rc2

老子叫甜甜 提交于 2019-12-20 02:50:06

问题


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)


回答1:


For getting request cookie value:

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

Setting response cookie:

HttpContext.Response.Cookies.Append("<key>", <value>, <options?>)


来源:https://stackoverflow.com/questions/37958343/cookies-in-asp-net-core-rc2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!