MVC 4 SimpleMembership - Por que WebSecurity.CurrentUserId -1 após o login
Eu estou tentando definir um cookie no login e ter problemas com a obtenção do ID do usuário atual após o login. No abaixo, intUserId é -1 e WebSecurity.IsAuthenticated é falso. Este não é o lugar correto para colocar este código? Depois disso, ele redireciona para a home page ... então não tenho certeza porque este não é o lugar correto.
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
//TODO: set current company and facility based on those this user has access to
int intUserId = WebSecurity.GetUserId(User.Identity.Name);
int intUserId2 = WebSecurity.GetUserId(model.UserName);
UserSessionPreferences.CurrentCompanyId = 1;
UserSessionPreferences.CurrentFacilityId = 1;
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}