在 ASP.NET Web 应用程序中使用哪个 Web 窗体事件来避免返回到之前的页面

问题描述

来自名为 pointA.aspx 的网络表单文件,cookie 将在其中初始化并发送到将接收和使用该 cookie 的网络表单 pointB.aspx。

发送 cookie 的方式是通过按钮的点击事件将其重定向到 webform pointB。

我需要实现相应的逻辑,以便一旦将所述cookie发送到webform pointB.aspx,它就无法返回或访问webform pointA.aspx

我尝试验证 cookie 的值,但没有成功,这是通过 IF 在页面加载中实现的(它仅在通过 F5 重新加载页面时才有效) )

webform pointA.aspx

       namespace Test
    {
       public partial class pointA : Page
    {       
        HttpCookie hamburger = new HttpCookie("hamburger","0");
        
        protected void Page_Load(object sender,EventArgs e)
        {           
            if (Request.Cookies["hamburger"].value == "5")
            {
                Response.Redirect("pointB.aspx");
            }
        }
        
        protected void btnLogin_Click(object sender,EventArgs e)
        {
            hamburger.Value = "5";
            hamburger.Expires = DateTime.Now.AddMinutes(40);
            Response.Cookies.Add(hamburger);
            Response.Redirect("pointB.aspx");
        }
    }
}

webform pointB.aspx

    namespace Test
     {
       public partial class pointB : Page
    {

        protected void Page_Load(object sender,EventArgs e)
        {
            if (Request.Cookies["hamburger"] != null)
            {
               txtLabelHamburger.text = Request.Cookies["hamburger"].value.ToString();
            }
 

        }
     }
    }

解决方法

为了避免嗅探代码以更改您的提交表单,这里有一种尝试方法。

1) On Form load pointA.aspx,create unique UUID/GUID hidden input in form 
   using server side and insert the record in a UniqueFormSubmit Table 

2) On form redirect to pointB.aspx,validate if unique UUID/GUID record existed in a 
   UniqueFormSubmit Table and status NOT COMPLETED,then mark it STATUS COMPLETED PROCESSED.  
   If record already exist in the table 
   with STATUS COMPLETED PROCESSED,then reject the re-submit form.