The F5 key will cause repeated submission of forms. I believe this problem has been encountered in Asp.net.
The most effective method is the one published on msdn.
The principle is as follows:
On the Asp.net page, there is a hidden field named _ viewstate, which stores the view status of the control on the current page. If the field is submitted by the submit button or the page is sent back, the value of this hidden field will change, but if it is refreshed by pressing the F5 key of the browser, the value of this hidden field will not change.
Based on the above principle, we only need to save the value of the last hidden domain on the page, and then judge and compare the value of the current hidden domain when executing the page, you can know which method the client uses to submit data.
However, the disadvantages of this method are also obvious:
The server needs to save additional data each time. To obtain the value of the hidden domain, it must be intercepted through httpmodule, which will inevitably affect the application.ProgramBecause the httpmodule is global and tested, the image cannot be displayed, and the third-party JavaScript library used will be ineffective.
Some time ago, I saw a new method.
By judging the header information in the request, we can prevent the two requests from being submitted repeatedly. However, you can carefully observe the accept value in headers, you will find that the first time you submit through the submit button, accept reflects the multimedia types acceptable in the current client environment, but the second time you submit by pressing F5 to refresh, its value is */*, indicating all.
Therefore, determine request. headers ["accept"]! = "*/*" To achieve the desired effect.