0

I have an MVC site (MVC 4) and have this problem that I need to prevent. Think of the site as an application process website (i.e you apply for something and need to fill out a bunch of details and going through a step by step process)

so, when the user hits submit on this page:

Qualification

it takes them to "select product" page. Then when they hit submit on select product, it takes them to a "quantities" page.

now, I have applied [NoCache] attributes to these action methods. a NoCache attribute is the following:

public sealed class NoCacheAttribute : ActionFilterAttribute
    {
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
            filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
            filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            filterContext.HttpContext.Response.Cache.SetNoStore();

            base.OnResultExecuting(filterContext);
        }
    }

This does work for what I am wanting (i.e don't cache the page).

The problem is, if they hit the back button, it either:

  • serves back from the local temp folders cache
  • reinvokes the action

I want to catch which page they just came from if they hit the back button so I can tell them they cant do that.

problem is, when this happens - the UrlReferrer is actually the page that got them to the page in the first place i.e:

Details -> Qualification -> select product -> quantities

if they go to qualification, then select product and on the select product page, they hit back in their browser, the qualification action method (GET) has the UrlReferrer of Details. This does make sense since technically it did come from it in the first instance.

how can I check if they hit the back button or came from another page (i.e select product)? I NEED to prevent this from happening and direct them to a custom page if they hit the back button in their browser.

thank you

Ahmed ilyas
  • 5,722
  • 8
  • 44
  • 72
  • Users LIKE to go back. It's us programmers who don't want it. And they outnumber us. Consider adjusting your process to handle the situation in a more user-friendly manner. – Sam Axe Jan 31 '14 at 04:07
  • cant adjust as its part of the process. all to do with application processing and id's etc... I understand what you mean but if you already submitted something, why go back and screw up the resubmission? just like if you are at a bank ATM, you cant really say to the ATM "hang on, I actually changed my mind and want to give back x amount for y amount". by trying to adjust to how stupid a user can be only causes MORE problems than to SOLVE problems – Ahmed ilyas Jan 31 '14 at 06:32
  • This answer and the one below it may give you some ideas. http://stackoverflow.com/a/961245/529665 – Sam Axe Jan 31 '14 at 07:01

0 Answers0