Reputation: 63
User.Identity.IsAuthenticated
always returns false
in my ASP.NET Web API project.
In account ApiController
I have following:
ClaimsIdentity identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() {
IsPersistent = isPersistent
}, identity);
After signing in, User.Identity.IsAuthenticated
is always false
in ApiController
but true
in MVC Controller.
Upvotes: 5
Views: 5453
Reputation: 4520
The ApiController has a User property and is available from:
base.User.Identity.IsAuthenticated
Upvotes: 7
Reputation: 99
var isAusorized = (Request.Properties["MS_HttpContext"] as HttpContextWrapper).User.Identity.IsAuthenticated;
Upvotes: 0
Reputation: 861
It's unable to use HttpContext property directly in APIControiller. To get this , you have to make use of Request property of type System.Net.Http.HttpRequestMessage. HttpRequestMessage has a Properties dictionary; you will find the value of the key MS_UserPrincipal holds your IPrincipal object.
Upvotes: 2