ASP. NET prevents repeated submission of forms by pressing F5

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.