Niklaus Wirth
Niklaus Wirth

Reputation: 870

ASP.NET Core HttpContext.User always empty

I have weird behavior using asp.net core 3.1 which is as follows When I called

enter image description here This is called in AccountController.Login action method The result return with Succeeded, and user will redirected to Dashboard/Index action method, however when I check HttpContext.User.Identity enter image description here

It always return with empty identity object that have default values for all its inner properties.

I tried to set the value manually but it still the empty object even when I set it to null

Here is full ConfigureService method that I use enter image description here

Upvotes: 2

Views: 3716

Answers (1)

Rena
Rena

Reputation: 36655

You need to be sure that call the middleware in the order like below: UseRouting, UseAuthentication, UseAuthorization, and UseEndpoints.

Reference:

https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-3.1&tabs=visual-studio#configure-identity-services

Upvotes: 6

Related Questions