Asp.net prevents refresh and resubmit to trigger background events

Source: Internet
Author: User

Asp.net background event binding is a very useful function. However, if you refresh the page after the page is submitted, the page will be re-posted and the background method will be called. This is the implementation of almost all browsers: After you submit a form in post mode, if you directly open F5 refresh, the form will be submitted again!

There are two solutions:

1. In simple cases, use respone. Redirect (URL) to redirect to the current page through get after your background event processing is complete.

2. If you cannot use the above redirection method in some cases, you can use the HTTP header's accept to determine whether the page is refreshed. When the page is refreshed, the value of accept is */*.

1 If (request. headers ["accept"] = "*/*")
2 {
3 // the current page is refreshed
4}

 

 

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.