Abrufen Userid aus einer Forderungen in einem cookie im Core, MVC

Möchte ich zum speichern einer Benutzer-id in einem cookie, in ASP.NET Kern MVC. Wo kann ich darauf zugreifen?

Login:

var claims = new List<Claim> {
    new Claim(ClaimTypes.NameIdentifier, "testUserId")
};

var userIdentity = new ClaimsIdentity(claims, "webuser");
var userPrincipal = new ClaimsPrincipal(userIdentity);
HttpContext.Authentication.SignInAsync("Cookie", userPrincipal,
    new AuthenticationProperties
    {
        AllowRefresh = false
    });

Logout:

User.Identity.GetUserId(); //<-- 'GetUserId()' doesn't exists!?

ClaimsPrincipal user = User;
var userName = user.Identity.Name; //<-- Is null.

HttpContext.Authentication.SignOutAsync("Cookie");

Es möglich in MVC 5 ------------------->

Login:

//Create User Cookie
var claims = new List<Claim>{
        new Claim(ClaimTypes.NameIdentifier, webUser.Sid)
    };

var ctx = Request.GetOwinContext();
var authenticationManager = ctx.Authentication;
authenticationManager.SignIn(
    new AuthenticationProperties
    {
        AllowRefresh = true //TODO 
    },
    new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie)
);

Bekommen UserId:

public ActionResult TestUserId()
{
    IPrincipal iPrincipalUser = User;
    var userId = User.Identity.GetUserId(); //<-- Working
}

Update - Added screenshot der Ansprüche, die null - - - - - - - -

userId ist auch null.

Abrufen Userid aus einer Forderungen in einem cookie im Core, MVC

InformationsquelleAutor radbyx | 2016-12-20
Schreibe einen Kommentar