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