在开发中有时并不希望页面被缓存,特别是弹窗。在弹窗页面中,加入以下方法。
这个问题(弹窗清除缓存)出现的条件:1、IE浏览器;2、弹窗形式为window.showModalDialog。当我们第二次打开页面的时候,会直接从缓存中读取,不再走Page_Load。
测试:FireFox没有问题。
方法一:
<head runat="server">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
</head>
方法二:
在后端代码中添加,建议放在Page_Load事件中
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Page.Response.Buffer = false;
Page.Response.Cache.SetNoStore();
}
}
方法三:
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
if (!IsPostBack)
{
}
}