title: Blazor Server: NavigationManager in Middleware
body: <p>I'm trying to create a httphandler in a Blazor Server app that handles all unsuccessful status codes. If a 401 is thrown, I want to redirect to a custom 401 page.</p>
  <p>For some reason, I cannot get the NavigationManager to work after depency injection. It looks like it does load the NavigationManager, but it never initializes it.</p>
  <pre><code>public class RichardsHandler : DelegatingHandler
  {
      protected readonly NavigationManager _navManager;
      public RichardsHandler(NavigationManager navigationManager)
      {
          _navManager = navigationManager;
      }
      protected override async Task&lt;HttpResponseMessage&gt; SendAsync(
      HttpRequestMessage request, CancellationToken cancellationToken)
      {
          var response = await base.SendAsync(request, cancellationToken);
  
          _navManager.NavigateTo(&quot;/401&quot;);
  
          return response;
      }
  }
  </code></pre>
  <p>I simply put the NavigateTo there to try and navigate to another page, but I always get a &quot;InvalidOperationException: 'RemoteNavigationManager' has not been initialized&quot; exception.</p>
  <p>Again, this is a Blazor Serverside app. Am I overlooking something or is this by design in the NavigationManager?</p>