[ASP.NET]防止F5

摘要:[ASP.NET]防止F5


 private void SetActionStamp()
    {
        Session["actionStamp"] = Server.UrlEncode(DateTime.Now.ToString());
    }

    void Page_PreRender(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            SetActionStamp();
        }
        ClientScript.RegisterHiddenField("actionStamp", Session["actionStamp"].ToString());
    }
    protected bool IsRefresh
    {
        get
        {
            if (HttpContext.Current.Request["actionStamp"] as string == Session["actionStamp"] as string)
            {
                SetActionStamp();
                return false;
            }
            else
            { return true; }

        }
    }