use*_*759 5 c# asp.net-mvc asp.net-web-api
User.Identity.IsAuthenticated总是false在我的 ASP.NET Web API 项目中返回。
在帐户中,ApiController我有以下内容:
ClaimsIdentity identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() {
IsPersistent = isPersistent
}, identity);
Run Code Online (Sandbox Code Playgroud)
登录后,User.Identity.IsAuthenticated总是false在ApiController
但true在 MVC 控制器中。
该ApiController有一个用户属性,可从:
base.User.Identity.IsAuthenticated
Run Code Online (Sandbox Code Playgroud)
它无法直接在 APIControiller 中使用 HttpContext 属性。要获得此信息,您必须使用 System.Net.Http.HttpRequestMessage 类型的 Request 属性。HttpRequestMessage有一个Properties字典;您会发现 MS_UserPrincipal 键的值保存着您的 IPrincipal 对象。
| 归档时间: |
|
| 查看次数: |
4685 次 |
| 最近记录: |