Accessing Username in C# server code

I am looking to access the username of the authenticated user in a OnXxxxsRead() partial method, but this.User.Name is null… Where should I look?


I have read and found this:

var userName = this.HttpContext.User.FindFirst(ClaimTypes.Name).Value;

but this does not work in my code because this.HttpContext.User.FindFirst(ClaimTypes.Name) returns a null…

Hi @semafox,

Could you please try decorating your controller with [Authorize(AuthenticationSchemes="Bearer")] e.g.

public partial class OrdersController 

This seems to be required for ASP.NET Core 2.0 applications (wasn’t required before).

Best regards,

Thank you, this worked.