Boas Enkler
Boas Enkler

Reputation: 12557

ASP.net 5 Identites , not everywhere authenticated

After signing a user in with the following code, i can see that User.Identity.IsAuthenticated is true. Also the UserName ist set.

  var result = await signInManager.PasswordSignInAsync(vm.UserName, vm.Password, vm.RememberMe, false);

But Identity in other apis are not set

var ident2 = Thread.CurrentPrincipal.Identity;
var ident3 = ClaimsPrincipal.Current.Identity;

They are all not authenticated. Is this as expected in a asp.net 5 application?

Upvotes: 1

Views: 107

Answers (2)

Kévin Chalet
Kévin Chalet

Reputation: 42080

Is this as expected in a asp.net 5 application?

Yes it is, since neither ClaimsPrincipal.Current nor Thread.CurrentPrincipal (used internally by ClaimsPrincipal.Current by default) are set by ASP.NET 5. To retrieve the user associated with the current request, your only option is to use HttpContext.User (which is not static).

It may change in the future, though: https://github.com/aspnet/Security/issues/322.

Upvotes: 1

Lee Dale
Lee Dale

Reputation: 1196

When you sign someone in and User.Identity.IsAuthenticated is true then this means that the HttpContext.User.Identity is set to the logged in user.

Thread.CurrentPrinciple will return the worker process user that is being used to host the application.

Upvotes: 1

Related Questions