Question

I have integrated Payment Gateway in my Web Application made in MVC4 Razor. After payment has been done successfully the user is redirected to the return URL..

Then i do some process like generating unique id ,sending payment details sms blah blah..

[NoCache]
public ActionResult IPGResponse()
        {
            //Send SMS..
            //Save Payment Response..etc

            return RedirectToAction("ThankyouUploadDocument");
        }

Then I redirect to another Action.

public ActionResult ThankyouUploadDocument()
        {
            //Do Something

            return View("ThankyouUploadDocument" , paymentViewModel);
        }

The problem is when user hit back .It goes to IPGResponse() and do all steps again .

I have also used [NoCache]..but it did not worked

I have to Restrict the user to go back to the IPGResponse() or Payment Gateway again..

Was it helpful?

Solution

This should prevent caching:

        HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        HttpContext.Response.Cache.SetValidUntilExpires(false);
        HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Response.Cache.SetNoStore();

and probably a good idea also server-check when form gets submitted and return error in case by some dark magic cache works. which it really shouldn't.

edit: this will prevent the browser's 'back' button from loading up cached page, which is what the question was about. Of course you would need check on page-enter to see if the transaction has already taken place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top