首页 新闻 搜索 专区 学院

cookie 删除失败

0
悬赏园豆:30 [已关闭问题]

在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");
    }

汉城的主页 汉城 | 初学一级 | 园豆:2
提问于:2009-02-08 00:28
< >
分享
其他回答(3)
0

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");
    }

路人.乙 | 园豆:227 (菜鸟二级) | 2009-02-08 09:13
0

看下

      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);
            }
        }

zjy | 园豆:3194 (老鸟四级) | 2009-02-09 09:16
0

studying....

Jared.Nie | 园豆:1940 (小虾三级) | 2009-02-09 11:21
0

我也遇到相关问题,不知道你解决没,分享下,谢谢

菱子 | 园豆:129 (初学一级) | 2012-04-01 14:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册