title: Custom ActionFilter for disabling the BACK button
body: <p>Currently working on an ASP.NET MVC 3.0 application and using <code>FormsAuthentication</code>.</p>
  
  <p>When the user clicks the Logoff link, it calls the following:</p>
  
  <pre><code>public ActionResult LogOff()
  {
      FormsAuthentication.SignOut();
      return RedirectToAction("Index", "Home");
  }
  </code></pre>
  
  <p>Works great! </p>
  
  <p>But if the user clicks the BACK button, he gets to see his previous page (although he won’t be able to do anything since the <code>[Authorize]</code> attribute is set) and we didn’t want that.</p>
  
  <p>After many searches and posts regarding this subject, I ended up creating a custom ActionFilter called <code>[NoCache]</code> which is placed right underneath each <code>[Authorize]</code> attribute I have.</p>
  
  <p>The <code>[NoCache]</code> attribute looks like this:</p>
  
  <pre><code>public class NoCacheAttribute : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
          HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
          HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
          HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
          HttpContext.Current.Response.Cache.SetNoStore(); 
      }
  }
  </code></pre>
  
  <p>It seems to work but I’m curious to know if this seems like the appropriate approach to use (or not). Are there any known issues I’m not aware of in using this technique?</p>
  
  <p>In addition, I’ve been told that if I had an SSL Certificate then I wouldn’t need to do this but instead, create and set an HTTP Header with <code>Cache-Control: no-cache</code> which would, ultimately, make <em>all</em> my https pages not cached. </p>
  
  <p>Can anyone confirm this?
  If the above is true, then why would I create a custom ActionFilter? </p>
  
  <p>Feel free to share any thoughts or better approaches…</p>
  
  <p>Keep in mind, the ultimate goal is to make sure a user does not see his previous page(s) when clicking the BACK button <em>after</em> he’s been signed off (<code>FormsAuthentication.SignOut();</code>)</p>
  
  <p>Thanks</p>