问题描述
如何在ASP MVC 6中使用cookie?我想设置和读取cookie变量.
How can i use cookies in ASP MVC 6? I want to set and read cookie variables .
HttpCookie类无法解析.
HttpCookie class can't be resolved .
仅以下几行有效,但添加后我找不到读取cookie的方法.Response.Cookies.Append("test","test");
Only the following line works but i couldn't find a way to read the cookie after adding it . Response.Cookies.Append("test", "test");
推荐答案
看看在官方MusicStore示例中如何使用cookie: https://github.com/aspnet/MusicStore/blob/a7ba4f8ffe5ed23b2a2d55e8e1226e64066a7a/Store/Cart/ping
Take a look at how cookies are used in the official MusicStore sample: https://github.com/aspnet/MusicStore/blob/a7ba4f8ffe5ed23b2a2d55e8e1226e64066a7ada/src/MusicStore/Models/ShoppingCart.cs#L152
public string GetCartId(HttpContext context)
{
var sessionCookie = context.Request.Cookies.Get("Session");
这篇关于ASP vnext中的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!