我想用cookie注册我网站中几个页面的参数.我try 了以下代码,但不符合我的要求:
public ActionResult Index(int? dep, int? cat)
{
......
string theDept = Request.QueryString["dep"];
HttpCookie cookie = new HttpCookie("search");
cookie.Values["dep_name"] = theDept;
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
return View();
}
师父:我在网站上读到的.
<%
HttpCookie cookie = Request.Cookies["search"] ;
if ((cookie != null) && (cookie.Value != ""))
{
Response.Write(cookie.Values["dep_name"].ToString() + "---" +
cookie.Values["cat_name"].ToString() + "---" + cookie.Values["brand"].ToString());
}
%>
问题:当我单击另一个Request.QueryString["dep"]
为空的页面时,我显示的cookie为空.
当我们还没有清除cookie时,如何将其存储在cookie中而不丢失?