在A页是添加一个 cookie值
在B页是判断cookie
在C页是删除cookie
问题 我点C页的 按钮 后 转到B页 通过B页的判断 应该转到A页去。。
但这个代码不知道为什么 转不过去。
更奇怪的是 B页的Request.Cookies["ID"].Expires 等于{0001-1-1 0:00:00}
A页--
protected void Button1_Click(object sender, EventArgs e)
{
Response.Cookies["ID"].Value = "001";
Response.Cookies["ID"].Expires = DateTime.Now.AddDays(1);
Response.Redirect("Default2.aspx");
}
B页----
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["ID"]==null)
{
Response.Redirect("Default.aspx");
}
else
{
if (string.IsNullOrEmpty(Request.Cookies["ID"].Value))
{
Response.Redirect("Default.aspx");
}
else
{
Response.Redirect("Default3.aspx");
}
}
}
}
C页----
protected void Button1_Click(object sender, EventArgs e)
{
Response.Cookies["ID"].Value = null;
Response.Cookies["ID"].Expires = DateTime.Now.AddDays(-1d);
Response.Cookies.Remove("ID");
Response.Redirect("Default2.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Cookies["ID"].Value = "";
Response.Cookies["ID"].Expires = DateTime.Now.AddDays(-1d);
//Response.Cookies.Remove("ID");
Response.Redirect("Default2.aspx");
}
看下
public static void ClearCookie(string cookieName)
{
if (HttpContext.Current.Request.Cookies[cookieName] != null)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];
cookie.Expires = DateTime.Today.AddDays(-1);
HttpContext.Current.Response.Cookies.Add(cookie);
}
}
studying....
我也遇到相关问题,不知道你解决没,分享下,谢谢