How to prevent data transfer if user press F5 or update in asp.net?

I had an asp.net form application. I have an error when a user presses F5 or updates, he will enter data from the last data entry. They are not there to prevent sending data if the user presses the F5 button or is updating?

+5
source share
3 answers

It is easy to reset to create a page for it in ASP.NET by redirecting to itself. Here are 3 ways to do this:

  • Response.Redirect (Request.Path);

In which the path to the request is presented in the following form: /MyApp/MyFile.aspx

  • Response.Redirect (Request.RawUrl);

In which not only the path is open, but also any request parameters: /MyApp/MyFile.aspx?foo=bar

  • Response.Redirect(Request.Url.ToString());

querystring, : MyServer/MyApp/MyFile.aspx? Foo =

+11
+5

There are several ways to prevent this. The simplest one is Response.Redirecton another page, which can be updated without consequences.

// process form post
Response.Redirect("anotherpage.aspx");
+1
source

All Articles