title: How to set Request.IsAuthenticated to true when I'm using cookies
body: <p>I assume that problem I'm describing is very common but I can't find any solution which would help me. I created a ASP.NET MVC project but instead of built-in authentication system I'd like to create my own one, since I have already a database which contains information about users (username, email address, password, etc.)</p>
  
  <p>I'd like to use FormsAuthentication and connect it to my own database which I assume I've already done, but everytime I'm sending a new request to the application the Request.IsAuthenticated property is always set as false.</p>
  
  <p>Here's the code I'm using:</p>
  
  <pre><code>    // GET: /Account/Login
      [AllowAnonymous]
      public ActionResult Login(string returnUrl)
      {
          ViewBag.ReturnUrl = returnUrl;
          return View();
      }
  
      //
      // POST: /Account/Login
      [HttpPost]
      [AllowAnonymous]
      [ValidateAntiForgeryToken]
      public ActionResult Login(LoginViewModel model, string returnUrl)
      {
          if (!ModelState.IsValid)
          {
              return View(model);
          }
          using (var db = new dbEntities())
          {
              var result = db.Person.Any(x =&gt; x.Email == model.Email &amp;&amp; x.Password == model.Password);
              switch (result)
              {
                  case true:
                      FormsAuthentication.SetAuthCookie(model.Email, true);
                      resetRequest();
                      return RedirectToLocal(returnUrl);
                  default:
                      ModelState.AddModelError("", "Invalid login attempt.");
                      return View(model);
              }
          }
      }
  
      private void resetRequest()
      {
          var authCookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
          if (authCookie != null)
          {
              FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
              if (authTicket != null &amp;&amp; !authTicket.Expired)
              {
                  var roles = authTicket.UserData.Split(',');
                  System.Web.HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(new FormsIdentity(authTicket), roles);
              }
          }
      }
  </code></pre>
  
  <p>And it works very well, before resetRequest() method is called the IsAuthenticated value is set as false, after it's called it's set as true. Problem is that when I'm getting redirected to main page via return RedirectToLocal(returnUrl) the property is false again and I don't know what to do to keep it set as true.</p>
  
  <p>Do I have to call method like resetRequest() on the begining of every method in my controller? I don't think that's an elegant solution. Can anyone please help me with that?</p>