How to supress re-post when refreshing a page - ASP.NET MVC - asp.net

I am building a wizard using asp.net mvc. currently when the user hits next (or previous) the form values are posted to an action which does any processing required and then renders the next view.
the problem i am having is that if the users hit refresh in that new view they get prompted to re-post the form values which causes a ton of problems.
In firefox i am getting the message: "To display this page, the application must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."
Is there any way to prevent users from being able to re-post back to the action?
Thanks in advance.

Using the PRG pattern.
http://en.wikipedia.org/wiki/Post/Redirect/Get

Related

asp.net redirection defect

I am working on asp.net application.the user is clicks on some link which is inside grid item template field. if he is not logged in then he redirects to login page. after log in he is properly coming back to same page;the problem is that "i have passed the value in querystring to the page where he click on the link and after loggedIn the grid is showing blank because that grid is not getting query string value" I think you understand my problem.plz share your helpful opinion.
http://www.aspdotnetfaq.com/Faq/what-is-the-difference-between-server-transfer-and-response-redirect-methods.aspx
It is not a defect, but the desired behavior of Response.Redirect.
Store value in session and retrieve it after he gets back successfully from the login page.

Page hangs when leaving it for a while using ASP.NET Ajax

I'm working on a business application using ASP.NET Ajax , NHibernate and Spring.Net, I've got an annoying problem. The problem is that when I leave page for about 5 minutes and then return back and try to make any action that posts back, it displays wrongly (if there are controls hidden by style it became visible). In addition, the page didn't post back to the server.
Also the problem happens when opening two different tabs, different pages (Each page uses session but different keys )
Thanks in advance
As you describe the problem, its sounds that connect the content of the page with the user cookie and session, and when the session expired the application did not take care to recreate it.
So the post back fail because the session data have been lost when the page ask for them / need them to work and display correct the results.
This is the issue that I diagnose, how you fix that is up to you :)
Possible solutions
Change the logic of the page creation.
While the user is on page do not let the session ends (not good practice)
Store the user data of the page, on a database - connected with the user, and delete it after some days if not have been updated.

Back Button History: Skipping Page After POST

Move backward through history skipping the same page with different query string
The above is similar to my question, but I'll be more specific as mine concerns POSTs:
Scenario:
User is on Product Listing page. (Shorts.aspx)
User picks a product and navigates to product detail page (Best-Cargo-Shorts.aspx)
User clicks add to cart which performs postback (POST) of form to same page. (Best-Cargo-Shorts.aspx) -- this now shows Details page again, but with an Added TO Cart message at the top.
Current Behavior:
After the Add TO Cart form post; when the user clicks the Back button they navigate back to the "pre-post" version of the same page.
Desire:
When a user clicks the BACK button, I'd like it to go to Shorts.aspx, NOT Best-Cargo-Shorts.aspx, effectively Skipping the "pre-POST" page, or more accurately NOT STORING the 2nd POSTed page (Best-Cargo-Shorts.aspx).
Furthermore, I always want to avoid that "Page Content Expired" message. I just never want the POSTed version of the page in history. In this way, the following could also be true.
Shorts.aspx > Best-Cargo-Shorts.aspx > Best-Cargo-Shorts.aspx [POST] > Cart.aspx
If on cart and BACK button is pressed, I want the browser to navigate to Best-Cargo-Shorts.aspx (without the POST).
Is this possible with C#? Furthermore, is there a non-javascript solution?
Thanks.
One common way of handling this is the Post-Redirect-Get pattern.
In essence, the target of a POST request always responds with a 303 See Other (if HTTP 1.1) or 302 Moved Temporarily (if HTTP 1.0) status code redirecting the request as a GET, and usually eliminating the expired POST page from history. Potential downsides include the form parameters possibly remaining attached to the GET as a query string, and I've no clue how well it would (or wouldn't) integrate with ASP.Net Forms, MVC, or other web frameworks.
Generally, you should be using the post-redirect-get pattern, i.e. after the user adds the item to the card using POST, redirect him to Best-Cargo-Shorts.aspx with 302.
Now to your question, I would use Ajax for the post. I cannot think of a cross-browser way to achieve the desired behaviour using only server side code.

Convert HTML Forms to ASP.NET forms with a silent post and response handler

I want to write a DotNetNuke module that can take an HTML form and parse or transform it into an asp.net form that would then do a HTTPPost to the page specified in the HTML Form's action property.
We regularly run into the need to use pre-existing forms (from existing sites and Service Providers like Paypal and Constant Contact). Currently, we either use an IFrame, manually convert the form into an ASP.NET user control, or use a forms module to recreate the form. It seems like it should be fairly easy to create an automated way to handle these with ASP.NET.
My quick plan:
1.) Admin Users will paste the form into a settings page and then click a convert button
2.) The code will parse the HTML and generate a ascx User Control from it and store the posting address. We may just have to add runat="server" into each of the form controls
3.) The admin user will be able to specify a variety of response codes and corresponding messages. (i.e. 1 -> "Thank you for your Donation", 2-> "We were not able to process your request at this time due to ...")
Users would then fill out the form and hit submit. The system would get the names and values of all form controls and Silent Post that to the posting address and get the response code and then display the corresponding message.
Any thoughts or suggestions of the best way to do this? Are there any tools that already do this or would be helpful?
Thanks,
David O'Leary

Detection of page refresh / F5 key in ASP.NET MVC 2

How would one go about detecting a page refresh / F5 key push on the controller handling the postback? I need to distinguish between the user pressing one of two buttons (e.g., Next, Previous) and when the F5 / page refresh occurs.
My scenario is a single wizard page that has different content shown between each invocation of the user pressing the "Next" or "Previous" buttons. The error that I am running into is when the user refreshes the page / presses the F5 key, the browser re-sends the request back to the controller, which is handled as a post-back and the FormCollection type is used to look for the "submitButton" key and obtain its value (e.g., "Next," "Send"). This part was modeled after the post by Dylan Beattie at How do you handle multiple submit buttons in ASP.NET MVC Framework?.
Maybe I'm trying to bend MVC 2 to where it isn't meant to go but I'd like to stay with the current design in that the underlying database drives the content and order of what is shown. This allows us to add new content into the database without modifying the code the displays the content.
Thanks,
Michael
The recommended way is to use PRG pattern - Post-Redirect-Get. Meaning: after submitting, redirect a client to Index or what, causing only reloading Index when user hits F5, not posting the data again.
Check this: http://en.wikipedia.org/wiki/Post/Redirect/Get
And this: http://www.google.sk/search?q=prg+mvc+asp.net

Resources