我的cookies没有过期,
我2pages
1page
generating cookies
我expire cookies
,第二页我正在尝试HttpCookie editorid = new HttpCookie("editorid");
editorid.Value = Convert.ToString(rr1.First().editor_id);
Response.Cookies.Add(editorid);
Response.Redirect("2page.aspx");
,然后将其重定向到生成但后面生成的页面点击浏览器该页面打开
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");
}
.cs代码“重定向并获得已过期”的位置在 2page.aspx
1page.aspx
点击 Linkbutton1 后,它会被重定向到2page.aspx
,但当我点击后退按钮时,会再次返回{{1}}
我应该如何使饼干过期?
答案 0 :(得分:3)
从您的描述中看来,当用户点击后退按钮时,页面会从后退按钮缓存中拉出来,这非常具有侵略性。
您可以尝试通过changing the Cache-Control
header阻止此缓存,在ASP.NET中,可以使用页面顶部的OutputCache
指令来完成此操作。
<%@ OutputCache Location="None" VaryByParam="None" NoStore="true" Duration="1" %>
答案 1 :(得分:1)
使用会话,这样可以获得更多控制权,并且可以将会话设置为null(如果不再使用)