title: How can I get the current user name in the C# code behind of Blazor?
body: <p>I have a Blazor server app with IIS Windows Authentication where I can get the current user in my razor page with following code, without problem:</p>
  <pre><code>&lt;AuthorizeView&gt;
          @context.User.Identity.Name
      &lt;/AuthorizeView&gt;
  </code></pre>
  <p>I need this user info also in the code behind C# Class of the razor page (razor.cs)
  I tried this but I always get null as active user:</p>
  <pre><code>using Microsoft.AspNetCore.Components.Authorization;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Http;
  namespace WebApplication7.Pages
  {  
  public partial class Explorer
  {
   public System.Security.Principal.IPrincipal User { get; set; }
   public static string CurrentUserName { get; set; }
   protected override async void OnInitialized() // = On Page Load
      {                   
          var authenticationState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
          CurrentUserName = authenticationState.User.Identity.Name;            
      }
   }
   }
  </code></pre>
  <p>I tried to use also 'context.User.Identity.Name' but I get always missing namespace error. What is wrong or missing in my code?</p>