[英]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?看起来声明是使用 ASP.NET Core (3.1) 授权的方式,但我的问题是我们如何才能拥有整数值而不仅仅是字符串? I want to store some IDs in the claims:
我想在声明中存储一些 ID:
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
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 .
因此,您可以将 userid 转换为字符串,并在另一端解码令牌,获取声明并在需要时再次转换为 int。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.