Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "User.Identity.IsAuthenticated" in Web API

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.

like image 699
user3405759 Avatar asked Mar 11 '14 11:03

user3405759


1 Answers

The ApiController has a User property and is available from:

base.User.Identity.IsAuthenticated
like image 189
OzBob Avatar answered Nov 08 '22 12:11

OzBob