【问题标题】:asp.net core razor view identify current authentication schemeasp.net core razor 视图识别当前身份验证方案
【发布时间】:2023-01-08 03:50:14
【问题描述】:

我正在尝试实施多种身份验证方案,一种是 asp.net 核心身份提供的默认电子邮件和密码,另一种是我使用自定义名称的自定义身份验证方案,但是当我尝试获取声明或验证我的自定义方案用户时

if (User.Identity.IsAuthenticated){
........ 
}

什么都没有发生,它总是返回 false。有什么方法可以检索我存储在此自定义方案名称中的声明!

我用这种方式创建了这个

await HttpContext.SignInAsync(
                        "my-employee-custom-auth",
                        new ClaimsPrincipal(claimsIdentity),
                        authProperties);

但是当我尝试使用 User claimsprincipal 时,我没有得到任何使用此 cookie 名称的信息。有没有办法在检索 claimsprincipal 之前声明方案?

任何帮助将不胜感激。

问候,

【问题讨论】:

  • 你是怎么做认证的,你能看看你的逻辑代码吗?

标签: asp.net-mvc entity-framework asp.net-core asp.net-identity


【解决方案1】:

如果我理解正确,您想创建自己的 AuthenticationScheme。 如果是这样,你可以在这篇文章中学习如何做https://referbruv.com/blog/implementing-custom-authentication-scheme-and-handler-in-aspnet-core-3x/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-23
    • 2019-08-31
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 2018-06-12
    • 2022-01-04
    相关资源
    最近更新 更多