This has been a problem for a while. Most people used this to get around this:
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(Now.AddSeconds(-1));
Response.Cache.SetNoStore();
}
This piece of code basically directs the current page, which expires immediately after its publication, and sets that the page does not cache any of its contents.
However, some browsers may ignore the page cache settings, and some users still manage to get away with submitting the form several times.
Workaround:
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(Now.AddSeconds(-1));
Response.Cache.SetNoStore();
if (Page.IsPostBack){
if (isPageExpired()){
Response.Redirect("expired.htm");
}
else {
Session("TimeStamp") = Now.ToString;
ViewState("TimeStamp") = Now.ToString;
}
}
}
private boolean isPageExpired()
{
if (Session("TimeStamp") == null || ViewState("TimeStamp") == null)
return false;
else if (Session("TimeStamp") == ViewState("TimeStamp"))
return true;
else
return false;
}
, , , , , isPageExpired. true, ; , : , .
isPageExpired , , . , ; .