Prevent sending when user clicks back button

I have a webpage that sends email to multiple users (online mailing list). After clicking the "Send" button and sending the email, a status page is displayed with the number of emails sent, errors and other information. If the user clicks the back button, the email is resent. How can I prevent this?

NOTE. The browser asks the user to "resend" or "resend" the data to the page before sending the email, but this does not stop my users from clicking it and then wondering why two copies of the email were sent.

Environment:

  • Server: C #, ASP.NET 2.0, IIS6
  • Client: any browser (I do not want a solution specific to IE, for example SmartNavigation).
+3
source share
1 answer

In your code, immediately after sending emails redirect 302 to the confirmation page:

protected void btnSend_Click(object sender, EventArgs e)
{
    SendManyEmails();
    Response.Redirect("confirmation.aspx");
}

With this kind of POST code, the original page will not be displayed in the browser history.

This generic pattern is known as Post / Redirect / Get pattern .

Bonus state retention information when executing Post / Redirect / Get

, POST - , . ASP.NET Page all Control, , ViewState.

- " " - , - POST - GET. - : RoR flash, ASP.NET MVC TempData. ASP.NET , , - .

Session POST, GET . , , Flash/TempData ASP.NET.

+16

Source: https://habr.com/ru/post/1723799/


All Articles