title: Using global variable in ASP.NET Core controller
body: <p>The question is simple but I don't know how use it.</p>
  
  <p>For example there is a controller</p>
  
  <pre><code>public class MainController : Controller
  {
      private int a;
  
      public IActionResult Index(bool set = true)
      {
          if (set) a = 10;
  
          return View(a)
      }
  }
  </code></pre>
  
  <p>If I get in Index page at first time, I set a = 10. And I get in Index page again (for example refresh Index page or paging in Index page, i.e. move in same page) Actually, I get in Index page with url : <code>~Index?set=False</code> after first access.</p>
  
  <p>Then the <code>a</code> has 0 (default for int variable). I did not know the Controller page (Controller class) is always initialized when I gen in it even when I move to same page. </p>
  
  <p>So, I want to use variable like global variable not using session.</p>
  
  <p>Is there any way?</p>