Asp.net prevents repeated submission due to page refresh or rollback, and asp.net page refresh
In projects, the same record is repeatedly added to the database after refresh, resulting in data duplication. How can we avoid these problems? Next we will discuss how asp.net can prevent repeated data submission caused by PAGE refresh or rollback:
In fact, asp.net's prevention of refresh is a common problem in asp.net development. There are usually multiple methods to achieve this: (The following are just some of my summary methods) incomplete, and I hope my friends can add more. Thank you.
1: Request Forwarding (that is, jump to another page immediately after the data is submitted to prevent the page from refreshing and sending back)
2: Do not save the cache Response. cache. setNoStore ", the data will not be submitted repeatedly, which will prevent repeated submission refresh.
3: One solution of MSDN: It is to redefine the System. web. UI. when a Page class is used to load a Page, it is a "refresh", "back" request, or a normal request. Other pages inherit the custom Page class.
(See: http://msdn.microsoft.com/zh-cn/library/ms379557 (VS.80). aspx)
Of course there are other solutions, and I hope my friends can come up with their own solutions. Thank you.
In aspnet, how does one prevent repeated submission due to page refresh or rollback?
Hello!
This problem has been studied by many people. In general, F5 is disabled, right-click is disabled, and the browser is forbidden to move backward. However, many of the effects are not obvious because there are too many types of browsers, some large websites or systems have dedicated persons to rewrite browsers and other tedious operations.
For small websites, I have a very simple method to redirect the page, that is, when you are on the current page, such as. after adding, changing, or deleting aspx, redirect the page again, Response. redirect (". aspx "); (the word may be incorrectly written. Check it by yourself). In this way, when you refresh or jump to another page, the page will be redirected and there will be no data on it!
Several solutions for aspnet to prevent repeated submission, refresh, and page expiration
Simple operation method: Add Response. Cache. SetNoStore () to anti-rollback and refresh Page_Load; // The variable "IsSubmit" stored in the Session indicates whether the submission is successful if (! IsPostBack) if (Session ["IsSubmit"] = null) Session. add ("IsSubmit", false); if (bool) Session ["IsSubmit"]) {// if the form data is submitted successfully, set "Session [" IsSubmit "]" to falseSession ["IsSubmit"] = false; // display the submitted success message TextBox1.Text = "* submitted successfully! "; // Response. write ("<script> document. write ('<div style = \ "position: relative; left: 10px; top: 10px; width: 90%; height = + 30px; \ "id = DivRule> <font style = \" font-size: 14pt; font-family:, Song MS; color: # 4E4E4E; line-height: 14pt \ "> warning: the webpage has expired </font> </div>" + // "<div id = Out0 style = \" position: relative; left: 20px; top: + 15px; width: 90%; \ "> the webpage you applied for was created with the information submitted in the form. The webpage is invalid.