title: What is the way in ASP.NET Core 3.0 to get current authenticated User username?
body: <p>I'm working on the latest ASP.NET Core 3.0 Angular template. What I need to know is how we can get authenticated user, username in <code>ActionFilterAttribute</code>. </p>
  
  <p>The <code>ClaimTypes.NameIdentifier</code> returns the current user id, and <code>ClaimTypes.Name</code> returns the username which is null.</p>
  
  <p>Here is my code:</p>
  
  <p><a href="https://i.stack.imgur.com/TA889.png" rel="noreferrer"><img src="https://i.stack.imgur.com/TA889.png" alt="enter image description here"></a></p>
  
  <p>where <code>getUser</code> has a <code>UserId</code> of <code>d15f997a-6f65-4eb2-aecb-8b525361ae50</code></p>
  
  <p>I've also register IHttpContextAccessor in the Startup class as follows:</p>
  
  <pre><code>public IServiceProvider ConfigureServices(IServiceCollection services)
  {
          services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
              options.UseSqlServer(
                  Configuration.GetConnectionString("DefaultConnection")));
  
          services.AddDefaultIdentity&lt;ApplicationUser&gt;()
              .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;();
  
          services.AddIdentityServer()
              .AddApiAuthorization&lt;ApplicationUser, ApplicationDbContext&gt;();
  
          services.AddAuthentication()
              .AddIdentityServerJwt();
  
          //Database Setup
          services.AddDbContext&lt;HashooDBContext&gt;(Configuration.GetConnectionString("DefaultConnection"));
  
          services.AddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();
  
          services.AddControllersWithViews();
          services.AddRazorPages();
          // In production, the Angular files will be served from this directory
          services.AddSpaStaticFiles(configuration =&gt;
          {
              configuration.RootPath = "ClientApp/dist";
          });
  
          return ContainerSetup.InitializeWeb(Assembly.GetExecutingAssembly(), services);
  }
  </code></pre>
  
  <p>Controller.cs:</p>
  
  <pre><code>[Authorize]
  [ApiController]
  [Route("api/[controller]/{companycode}")]
  public class DashboardTransactionsController : ControllerBase
  {
      [CustomAuthorizationFilter("companycode")]
      public string Get()
      {
          return "Welcome";
      }
  }
  </code></pre>
  
  <p>Please let me know what am I doing wrong?</p>