我的 cookie 没有过期,
我在 1page 中有 2pages 我正在 generating cookies 并且在第 2 页我正在尝试 expire cookies然后将其重定向到生成它的页面,但在浏览器的后退单击该页面打开
.cs 代码 生成 位于 1page.aspx
HttpCookie editorid = new HttpCookie("editorid");
editorid.Value = Convert.ToString(rr1.First().editor_id);
Response.Cookies.Add(editorid);
Response.Redirect("2page.aspx");
.cs 代码 在 2page.aspx 中“redirected 并 expired” p>
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["editorid"] != null)
{
}
else
{
Response.Redirect("1page.aspx");
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Cookies["editorid"].Expires = DateTime.Now.AddSeconds(-1);
Response.Redirect("1page.aspx");
}
点击 Linkbutton1 它被重定向到 1page.aspx 但是当我点击后退按钮时它又回到 2page.aspx
我应该如何使 cookie 过期?
请您参考如下方法:
从您的描述看来,当用户单击后退按钮时,页面会从后退按钮缓存中拉出,这非常激进。
您可以尝试通过 changing the Cache-Control header 来阻止此缓存, 在 ASP.NET 中,这可以使用页面顶部的 OutputCache 指令来完成。
<%@ OutputCache Location="None" VaryByParam="None" NoStore="true" Duration="1" %>
