ASP.NET核心rc2中的Cookie [英] Cookies in ASP.NET Core rc2
问题描述
有人可以解释如何在ASP.NET Core rc2应用程序中存储和获取Cookie吗?我只能找到旧的 HttpContext.Response.Cookies.Get
和添加
方法的过时信息,存在于Core。另外, HttpCookie
类似乎也不存在。
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.
什么是新的cookie类,
What is the new cookie class and how can I get and add one?
(注意:我不是特别考虑认证Cookie,只是一般的数据cookie)
(Note: I am not specifically taking about authentication cookies, just general data cookies)
推荐答案
对于获取请求cookie值:
For getting request cookie value:
HttpContext.Request.Cookies["<key>"]
设置响应cookie:
Setting response cookie:
HttpContext.Response.Cookies.Append("<key>", <value>, <options?>)
这篇关于ASP.NET核心rc2中的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!