title: There is no registered service of type 'Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider'
body: <p>While trying to find an answer to this question here: <a href="https://stackoverflow.com/questions/60624778/how-to-implement-server-side-blazor-custom-authorization-provider-correctly">How to implement server side blazor Custom Authorization Provider Correctly</a> I have encountered a new error, that I am unsure how to resolve. Taking the template from @Henk Holterman's comment here: <a href="https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-2-release-now-available/" rel="nofollow noreferrer">https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-2-release-now-available/</a> I have been trying to develop some understanding how to implement web assembly blazor &amp; server-side blazor, and the differences between the two. </p>
  
  <p>Locally I can run my project and everything works as expected, I can login register and authorize a user. Once I deploy my application to IIS I start to receive WASM errors in console regarding no registered service 'AuthenticationStateProvider'.</p>
  
  <p>When I first deployed my application to IIS I also had issues with the appsettings.json file regarding the IdentityServer section, and I am wondering if I have broken something. The only section that I added was the "Key" section because I was receiving errors for no key filename defined. Which lead me to a stackoverflow post here: <a href="https://stackoverflow.com/questions/56094788/identityserver4-not-working-in-production">IdentityServer4 not working in production</a>
   to help resolve by exporting ssl cert to use as a file, which I then included in my project directory on IIS.</p>
  
  <p>server-side appsettings.json</p>
  
  <pre><code>{
    "ConnectionStrings": {
      "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-BlazorApp3.Server-A7F1C813-7F5D-4B96-8663-B8FA2E1472E8;Trusted_Connection=True;MultipleActiveResultSets=true"
    },
    "Logging": {
        "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
        }
      },
     "IdentityServer": {
      "Clients": {
        "BlazorApp3.Client": {
        "Profile": "IdentityServerSPA"
      }
     },
     "Key": {
        "Type": "File",
        "FilePath": "CertName.pfx",
        "Password": "CertPassword"
      }
    },
    "AllowedHosts": "*"
  }
  </code></pre>
  
  <p>server-side blazor startup.cs
  I have included app.UsePathBase("client-side-blazor") here because in IIS my application is not at the root node. It is a sub node of a site.</p>
  
  <pre><code> public void ConfigureServices(IServiceCollection services)
      {
          services.AddLogging();
  
          services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
              options.UseSqlServer(
                  Configuration.GetConnectionString("DefaultConnection")));
  
          services.AddDefaultIdentity&lt;ApplicationUser&gt;(options =&gt; options.SignIn.RequireConfirmedAccount = true)
              .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;();
  
          services.AddIdentityServer()
              .AddApiAuthorization&lt;ApplicationUser, ApplicationDbContext&gt;();
  
          services.AddAuthentication()
              .AddIdentityServerJwt();
  
          services.AddControllersWithViews();
          services.AddRazorPages();
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
              app.UseDatabaseErrorPage();
              app.UseWebAssemblyDebugging();
          }
          else
          {
              app.UseExceptionHandler("/Error");
              // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
              app.UseHsts();
          }
  
          app.UsePathBase("/client-side-blazor");
  
          app.UseHttpsRedirection();
          app.UseBlazorFrameworkFiles();
          app.UseStaticFiles();
  
          app.UseRouting();
  
          app.UseAuthentication();
          app.UseIdentityServer();
          app.UseAuthorization();
  
          app.UseEndpoints(endpoints =&gt;
          {
              endpoints.MapRazorPages();
              endpoints.MapControllers();
              endpoints.MapFallbackToFile("index.html");
          });
      }
  </code></pre>
  
  <p>client-side webassembly blazor program.cs</p>
  
  <pre><code>public static async Task Main(string[] args)
      {
          var builder = WebAssemblyHostBuilder.CreateDefault(args);
          builder.RootComponents.Add&lt;App&gt;("app");
  
          builder.Services.AddBaseAddressHttpClient();
  
          //builder.Services.AddAuthorizationCore();
  
          builder.Services.AddApiAuthorization();
  
          await builder.Build().RunAsync();
      }
  </code></pre>
  
  <p>builder.Services.AddAuthorizationCore() is commented out above, been trying to follow some other SO posts regarding my current issue.</p>
  
  <p>client blazor index.html</p>
  
  <pre><code>&lt;base href="/client-side-blazor/"/&gt; 
  </code></pre>
  
  <p>As a side note, it is still a little unclear what project to publish when creating a web assembly blazor project. In the references the server-side project has the client dll which makes my think that I should publish the server project, but I'm understanding from documentation that I could also deploy/publish just the web assembly project by itself (maybe as a stand alone project with no Authentication/Authorization). Any extra useful information that is easy to swallow would be greatly appreciated. </p>
  
  <p>Links I have used thus far in my research:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/blazor/?view=aspnetcore-3.1" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/blazor/?view=aspnetcore-3.1</a></p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/security/blazor/webassembly/standalone-with-authentication-library?view=aspnetcore-3.1" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/security/blazor/webassembly/standalone-with-authentication-library?view=aspnetcore-3.1</a> </p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/security/blazor/webassembly/hosted-with-identity-server?view=aspnetcore-3.1" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/security/blazor/webassembly/hosted-with-identity-server?view=aspnetcore-3.1</a></p>