【问题标题】:which Web Form Event use in ASP.NET web app to avoid return to a page previous在 ASP.NET Web 应用程序中使用哪个 Web 窗体事件来避免返回上一页
【发布时间】:2021-09-10 07:55:08
【问题描述】:

来自名为 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();
            }
 

        }
     }
    }

【问题讨论】:

    标签: asp.net asp.net-mvc webforms page-lifecycle page-load-time


    【解决方案1】:

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

    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.
    

    【讨论】:

    • 我没有完全理解你给我的答案,事实上我完全只是一个提交表单,但我感谢你投入的时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 2020-01-03
    • 2012-12-11
    • 1970-01-01
    相关资源
    最近更新 更多