title: setting HttpContext.Current.User
body: <p>I am developing an asp.net mvc 3.0 application which has a simple authentication process. User fills a form which is sent to server by ajax call  and gets response, but the problem here is that using the following method :</p>
  
  <pre><code>FormsAuthentication.SetAuthCookie(person.LoginName,false);
  </code></pre>
  
  <p>is not enough to fill 'HttpContext.Current.User' and it needs the below method to be run :</p>
  
  <pre><code>FormsAuthentication.RedirectFromLoginPage("...");
  </code></pre>
  
  <p>Problem here is that as i mentioned, the loggin form uses an ajax form, and get responses with json, so redirecting is not possible.</p>
  
  <p>How could I fill 'HttpContext.Current.User' ?</p>
  
  <p>Thanks.</p>
  
  <p>Update :</p>
  
  <p>Here is register method :</p>
  
  <pre><code> [HttpPost]
          public ActionResult Register(Person person)
          {
              var q = da.Persons.Where(x =&gt; x.LoginName == person.LoginName.ToLower()).FirstOrDefault();
  
              if (q != null)
              {
                  ModelState.AddModelError("", "Username is repettive, try other one");
  
                  return Json(new object[] { false, this.RenderPartialViewToString("RegisterControl", person) });
              }
              else
              {
                  if (person.LoginName.ToLower() == "admin")
                  {
                      person.IsAdmin = true;
                      person.IsActive = true;
                  }
  
                  da.Persons.Add(person);
  
                  da.SaveChanges();
  
                  FormsAuthentication.SetAuthCookie(person.LoginName,false);
  return Json(new object[] { true, "You have registered successfully!" });
  
  }
  
  }
  </code></pre>