首页 新闻 会员 周边

User.Identity.IsAuthenticated 时如何指定 authentication scheme

0
悬赏园豆:30 [已解决问题] 解决于 2022-09-03 19:30

在 ASP.NET Core 中在 Authorize 时可以指定 authentication scheme,请问在 User.Identity.IsAuthenticated 时如何指定?

[Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
dudu的主页 dudu | 高人七级 | 园豆:30994
提问于:2022-09-01 09:48

ClaimsIdentity 中 User.Identity.IsAuthenticated 对应的实现是 !string.IsNullOrEmpty(_authenticationType)

dudu 1年前
< >
分享
最佳答案
0

通过 [Authorize] 结合 [AllowAnonymous] 解决了

[Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
[AllowAnonymous]
public IActionResult IsAuthenticated()
{
    return User.Identity.IsAuthenticated ? NoContent() : Unauthorized();
}
dudu | 高人七级 |园豆:30994 | 2022-09-03 19:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册