title: How to enable/fix windows authentication in Blazor Server-Side App?
body: <p>When we created our server-side blazor app (ASP.NET Core Web App) initially we did not enable authentication. We would like to enable windows authentication now.</p>
  
  <p>I created a test web app with windows authentication and tried adding missing bits into our existing web app. Below are the changes that I made:</p>
  
  <ol>
  <li>Modified app.razor to include cascadingauthenticationstate</li>
  </ol>
  
  <pre><code>&lt;Router AppAssembly="@typeof(Program).Assembly"&gt;
          &lt;Found Context="routeData"&gt;
              &lt;AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /&gt;
          &lt;/Found&gt;
          &lt;NotFound&gt;
              &lt;CascadingAuthenticationState&gt;
                  &lt;LayoutView Layout="@typeof(MainLayout)"&gt;
                      &lt;p&gt;Sorry, there's nothing at this address.&lt;/p&gt;
                  &lt;/LayoutView&gt;
              &lt;/CascadingAuthenticationState&gt;
          &lt;/NotFound&gt;
      &lt;/Router&gt;
  </code></pre>
  
  <ol start="2">
  <li>Added missing imports in _imports.razor</li>
  </ol>
  
  <pre><code>@using Microsoft.AspNetCore.Authorization
  @using Microsoft.AspNetCore.Components.Authorization
  </code></pre>
  
  <ol start="3">
  <li>Tried fetching current windows identity using below code block in a razor component:</li>
  </ol>
  
  <pre><code>@code {
      [CascadingParameter]
      private Task&lt;AuthenticationState&gt; authenticationStateTask { get; set; }
  
      private async Task LogUsername()
      {
          var authState = await authenticationStateTask;
          var user = authState.User;
  
          if (user.Identity.IsAuthenticated)
          {
              Console.WriteLine($"{user.Identity.Name} is authenticated.");
          }
          else
          {
              Console.WriteLine("The user is NOT authenticated.");
          }
      }
  }
  </code></pre>
  
  <p>When I run the web app locally in Visual Studio 2019 preview, I am always ending up with an empty identity name. And, IsAuthenticated is always false.
  However, if I run the test web app locally, it gets the correct identity name.</p>
  
  <p>Does anyone know what I am missing in my existing web app?</p>
  
  <p>Thanks!</p>