日期:2014-05-17  浏览次数:20560 次

为什么cookie删除不掉?
点击button1把cookie的Expires设置为以前的日期,但好像不起作用。
C# code
public partial class Result : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["MyCookie"]!=null)
        {
            Label1.Text = Request.Cookies["MyCookie"].Value;
        }
        else
        {
            Label1.Text = "No cookies";
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Request.Cookies["MyCookie"]!=null)
        {
            Request.Cookies["MyCookie"].Expires = DateTime.Now.AddDays(-1);
            Response.Redirect("Result.aspx");
        }
    }
}



------解决方案--------------------
Request.Cookies["MyCookie"].Expires = DateTime.Now.AddDays(-1); 写错了
应该是Response.Cookies[]