gpt4 book ai didi

c# - 如何在Web API中使用 "User.Identity.IsAuthenticated"

转载 作者:行者123 更新时间:2023-12-02 02:18:23 25 4
gpt4 key购买 nike

User.Identity.IsAuthenticated 在我的 ASP.NET Web API 项目中始终返回 false

在帐户 ApiController 中,我有以下内容:

ClaimsIdentity identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); 
AuthenticationManager.SignIn(new AuthenticationProperties() {
IsPersistent = isPersistent
}, identity);

登录后,ApiController 中的 User.Identity.IsAuthenticated 始终为 false但 MVC Controller 中为 true

最佳答案

ApiController具有 User 属性,可从以下位置获取:

base.User.Identity.IsAuthenticated

关于c# - 如何在Web API中使用 "User.Identity.IsAuthenticated",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22324141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com