i have a form which allows the user to key in the data and then submit. if everything works well on this action result, then i will redirect the user back to a thank you pag
This solution works perfectly for both the whole controller or a specific action, simply add [NoCache]
///
/// Prevent a controller or specific action from being cached in the web browser.
/// For example - sign in, go to a secure page, sign out, click the back button.
///
///
public class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
var response = filterContext.HttpContext.Response;
response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
response.Cache.SetValidUntilExpires(false);
response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.Cache.SetNoStore();
}
}
And in your code:
[NoCache]
[Authorize]
public class AccountController : Controller
{ ... }
Originally posted here: MVC Back button issue