James
James

Reputation: 82096

ASP.NET How can I disable re-sending of request to server on refresh?

I am developing a page whereby users can login and demo some pieces of functionality. I only want to allow the user to demo this once per day.

A small example:

I have a web page with 3 buttons (relating to 3 different scenarios). On page load, I look up the database and check if the current logged in user has run any one of the 3 scenarios available (via an audit table). Each button is enabled/disabled based on the results. If any buttons are enabled, then they have not run that demo yet. By clicking the relative button, the demo runs a record is written into the Audit Table, and the button is disabled.

This was working ok, however, I realised that when I refresh the page (and confirm I want to re-submit the information) the demo runs again.

How can I stop this from happening? I need to only allow the user to run the demo once!

Thanks.

Upvotes: 1

Views: 2170

Answers (2)

womp
womp

Reputation: 116977

I would suggest that you change your form submission to use the Post/Redirect/Get pattern to avoid a resubmission if they hit refresh on the demo page.

Also, it seems like you should just be able to change the code at the point where it writes the record into the audit table to check to see if the record already exists, and if so, return a different result. I'd be pretty wary about this approach though. The "refresh" functionality of the browser isn't generally something you should be trying to prevent. What happens if a user hits "refresh" in the middle of their demo?

Upvotes: 2

BlackTigerX
BlackTigerX

Reputation: 6146

you can check not only on the page load to enable/disable the buttons, but on the button events, you can verify if that task has already been performed

Upvotes: 0

Related Questions