Keep in mind that the UseAuthentication
, UseRouting
and UseAuthorization
middleware must in correct in order for the ASP framework properly inject the identity context to http request.
It should look like this: (.NET Core 3.1)
Edit: the same code applies to .NET 5 & .NET 6
app.UseAuthentication();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});