title: MVC Login screen keeps showing up when switching pages
body: <p>Currently learning stuff with MVC and at the point of adding a login screen before the users are able to browse the site menu.
  I googled around and found a way to add authentication which only by adding this on top of HomeController:</p>
  
  <pre><code>[Authorize]
  </code></pre>
  
  <p>I also added this on web.config:</p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
    &lt;forms loginUrl="~/Account/Login" timeout="2880"/&gt;
  &lt;/authentication&gt;
  </code></pre>
  
  <p>Now the login works, but as soon as I change page(s), it will ask for login again and it will not be redirected to the page I was last on.</p>
  
  <p>How is it to retain the logged user session in MVC?</p>
  
  <p>EDIT: code for the login</p>
  
  <pre><code>//Login
      public ActionResult Login()
      {
          return View();
      }
  
      [HttpPost]
      public ActionResult Login(UserAccount user)
      {
          using (OurDbContext db = new OurDbContext())
          {
              var usr = db.userAccount.Single(u =&gt; u.Username == user.Username &amp;&amp; user.Password == user.Password);
              if (usr != null)
              {
                  Session["UserID"] = usr.UserID.ToString();
                  Session["Username"] = usr.Username.ToString();
                  return RedirectToAction("Index");
              }
              else
              {
                  ModelState.AddModelError("", "Username or Password is wrong.");
              }
          }
          return View();
      }
      public ActionResult LoggedIn()
      {
          if (Session["UserId"] != null)
          {
              return View();
          }
          else
          {
              return RedirectToAction("Login");
          }
      }
  </code></pre>