简体   繁体   English

ASP.NET Core 声明值的 Int32

[英]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.

相关问题 对于asp.net中的Int32,值太大或太小 - Value was either too large or too small for an Int32 in asp.net 异常:对于 asp.net 中的 Int32,值太大或太小? - Exception:Value was either too large or too small for an Int32 in asp.net? ASp.net WebForms C#将字符串转换为Int32所有方式均不起作用 - ASp.net WebForms C# Convert String To Int32 All ways are not working 如何通过Asp.net中的SqlDataSource存储过程参数将Int32输入发送到数据库 - How to send Int32 input to database through SqlDataSource stored procedure parameter in Asp.net ASP.NET Web API - 没有“MediaTypeFormatter”可用于读取“Int32”类型的对象 - ASP.NET Web API - No 'MediaTypeFormatter' is available to read an object of type 'Int32' ASP.NET Core中基于声明的授权 - Claim based authorization in ASP.NET Core ASP.NET 核心 - 无法在属性“MerchantStatus”上设置“System.Int32”类型的默认值“1” - ASP.NET Core - Cannot set default value '1' of type 'System.Int32' on property 'MerchantStatus' .net-core 中 Int32 的真正实现在哪里 - where is the real implementation of Int32 in .net-core 有什么方法可以将非Int32值用于ASP中的Cellspacing? - Is there any way to use a non Int32 value for Cellspacing in ASP? 如何检查API请求中的值声明(ASP.NET Core 2.2) - How to check claim for value in API request (ASP.NET Core 2.2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM