Я использую приведенный ниже код
var authenticationManager = System.Web.HttpContext.Current.GetOwinContext().Authentication;
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, "username"));
claims.Add(new Claim(ClaimTypes.Email, "username@gmail.com"));
var userIdentity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = true }, userIdentity);
ClaimsPrincipal principal2 = new ClaimsPrincipal(userIdentity);
System.Threading.Thread.CurrentPrincipal = principal2;
System.Web.HttpContext.Current.User = principal2;
var test = System.Web.HttpContext.Current.User.Identity.IsAuthenticated; //this resolves to true here
return RedirectToAction("List"); // redirecting to action
Теперь, после добавления сведений о претензиях, я перенаправляю на действие.Когда он перенаправлен, User.Identity.IsAuthenticated
становится ложным.
public ActionResult List()
{
var claimsIdentity = User.Identity as ClaimsIdentity;
var test = System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
//this resolves to false here
string email = claimsIdentity?.FindFirst(c => c.Type == System.IdentityModel.Claims.ClaimTypes.NameIdentifier)?.Value;
//this is null
}