hyden97
hyden97

Reputation: 153

How to propertly retrieve the user in Blazor

I'am new in Blazor(server) and in ASP.NET Identity. I searched on internet how to retrieve the current logged in user. I'am using ASP.NET IDENTITY with the built-in functions. And I saw people that use SignInMananger and the AuthenticationState, or even the HttpContext. Now my question is: what's the difference, the advantages of using the first over the other?

Upvotes: 1

Views: 536

Answers (1)

MrC aka Shaun Curtis
MrC aka Shaun Curtis

Reputation: 30036

Use the Authentication State - see this Ms Docs document which you've probably already read : https://learn.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-6.0.

SigninManager isn't really designed to work directly with Blazor - see this document that describes the issues. : https://startblazoring.com/Blog/SignInManager

HttpContext - The default Authentication State Provider does the work for you. It builds the ClaimsPrincipal object that represents the user from the HttpContext.

Upvotes: 1

Related Questions