我正在创建一个 cookie 并在其中获取一个文本框值。我需要使其过期,然后必须通过检查它是否已过期来打印一条消息。我正在执行以下操作
HttpCookie usercookie = new HttpCookie("userinfo");
Response.Cookies["gettingusername"].Value = textbox_username.Text;
Response.Cookies["gettingusername"].Expires = DateTime.Now;
Response.Cookies.Add(usercookie);
if (Request.Cookies["gettingusername"]!=null)
{
Response.Write("Cookie is Not Expired");
}
else
{
Response.Write("Cookie Expired");
}
但它总是说:-
Cookie is Not Expired
我是新手。请帮忙。提前致谢。