asp.net 页面重定向时 MVC cookie 为空

asp.net MVC cookie is null while page is redirecting

我正在 Pagan 中创建 cookie,点击此处的页面 link 时,它会重定向到页面 A。但是我没有在 PageA 中看到 cookie。我不确定我在这里遗漏了什么。

 [HttpGet]
        public ActionResult PageA()
        {             

            if (Request.Cookies["bCookie"] != null) { 
           //code
            }    
            return ActionResult(View(PageA));
        }


        [HttpPost]
        public ActionResult PageB(Model bCookieM)
        {
            HttpCookie bCookie= new HttpCookie("bCookie");
            bCookie.Value = bCookieM.ToString();

            Response.Cookies.Add(bCookie);                      

            return View(PageB);
        }

来自文档:如果您没有设置 cookie 的过期时间,则会创建 cookie,但不会将其存储在用户的硬盘上。相反,cookie 作为用户会话信息的一部分进行维护。当用户关闭浏览器时,cookie 将被丢弃。

使 cookie 持久化(24 小时)。做这样的事情:

Response.Cookies["userName"].Value = userName;
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);

HttpCookie bCookie = new HttpCookie("bCookie");
bCookie.Value = bCookieM.ToString();
bCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(bCookie);