Asp.net mvc controller 中如何正确存取cookie

我是这样写的 : 
//以下是存cookie, 假设这是些在controllerA中,运行项目首先会走过这段代码,也就是cookie里面现在是有值的。
HttpCookie cookie = new HttpCookie("xx");
xx.Name = "Name";
xx.Expires = DateTime.Today.AddDays(365);
xx.Values.Add("xx_Id", "Id"); 
Response.AppendCookie(cookie); 
//以下是取cookie,假设是在controllerB中,运行完项目当我进行某一操作时,会走下面这段代码。 问题是 为什么现在的Request.Cookies["xx"] 是空的,???求解啊!!
if (Request.Cookies["xx"] != null) {
string X = Request.Cookies["xx"]["xx_Id"].ToString();}

慕田峪7331174
浏览 1937回答 2
2回答

慕标琳琳

HttpContext.Current.Request.Cookies["cook"];
打开App,查看更多内容
随时随地看视频慕课网APP