title: Store session variable in action filter or static method
body: <p>Right now I am using a session variable to store a boolean value which I then use in my views.  I know that HttpContext.Session[] variables are static, but does that mean I need to store them in a static method, or can I keep them in my action filter and call them directly from there?</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>public class AuthorizationFilterAttribute : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          base.OnActionExecuting(filterContext);
  
          // If not authorized, redirect to login page
          if (true)
          {
              authorized = false;
              filterContext.HttpContext.Session["authorized"] = authorized;
  
  
              filterContext.Result = new RedirectResult("https://www.website.com");
          }
          else
          {
              filterContext.HttpContext.Session["authorized"] = authorized;
          }
  ...
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>@{var authorized = (bool)Session["authorized"];}
  @if (authorized != null)
  {
      if (authorized == true)
      {
          &lt;li&gt;&lt;a href="/"&gt;Download&lt;/a&gt;&lt;/li&gt;
      }  
  }
  </code></pre>
  
  <p>Should I be storing my session variables in static methods like below and calling them, instead of what I do above?</p>
  
  <pre><code>    public static bool Authorized(){
          return (bool)HttpContext.Current.Session["authorized"];
      }
  </code></pre>