title: Making pages that can be displayed only if logged in - ASP.NET Core MVC
body: <p>I have always been programming with ASP.NET Web Forms. Everything was simpler but now for having better performance and modern software, I decided to switch to ASP.NET MVC.</p>
  <p>I managed to understand most of the concepts but due to lack of Page Lifecyle in MVC, I am having troubles verifying whether the user has logged in.</p>
  <p>Let me give you an example:</p>
  <p>In ASP.NET Web Forms, I use to make a login page where if the user exists and has given proper credentials, the program would create a <code>Session</code> variable like this: <code>Session[&quot;UserID&quot;] = 3; </code></p>
  <p>And when the user is navigated to his or her account page, the a code like the one below would check if the user is logged in:</p>
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
          if(Session[&quot;UserID&quot;]==null)
          {
               Response.Redirect(&quot;/login.aspx&quot;);
          }
      }
  </code></pre>
  <p>how to make the same thing in MVC?</p>