简体   繁体   中英

Int32 for ASP.NET Core claim value

It looks like claims are way to go with ASP.NET Core (3.1) authorization, but my question is how can we have integer values not only strings? I want to store some IDs in the claims:

var userid = 123;  // try "123"
var claimsIdentity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userid, ClaimValueTypes.Integer32));

Or any better way to do it? TIA

The claims can only be represented as strings. So you can convert userid to string , and on other side decode token , get claim and convert to int again if needed .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM