title: System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String' with .NET 5
body: <p>I've been implementing IdentityServer4 to provide authorization for my React application. I have this working in my local dev environment, but am running into issues after deployed to IIS in Windows Server 2016. I am able to generate an access token via the /connect/token endpoint, but when I attempt to access a protected API using the token I get the following exception:</p>
  <pre><code>System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String'.
   ---&gt; System.IO.IOException: IDX20804: Unable to retrieve document from: 'System.String'.
   ---&gt; System.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (dev-drydata-auth.universal-compliance.com:443)
   ---&gt; System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
     at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
     at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
     at System.Net.Sockets.Socket.&lt;ConnectAsync&gt;g__WaitForConnectWithCancellation|283_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
     at System.Net.Http.HttpConnectionPool.DefaultConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
     at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
     --- End of inner exception stack trace ---
     at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
     at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
     at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
     at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
     at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
     at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
     at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
     at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
     at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
     --- End of inner exception stack trace ---
     at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
     at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
     at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
     --- End of inner exception stack trace ---
     at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
     at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
     at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
     at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
     at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
     at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
     at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext context)
     at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
     at NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.Invoke(HttpContext context)
     at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext)
     at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.&lt;Invoke&gt;g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
     at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
     at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.&lt;Invoke&gt;g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
     at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
  </code></pre>
  <p>My ConfigureServices as follows:</p>
  <pre class="lang-cs prettyprint-override"><code>public void ConfigureServices(IServiceCollection services)
  {
      ConfigureDryDataServices(services);
  
      services.AddControllersWithViews();
  
      services.AddCors(options =&gt;
      {
          options.AddPolicy(&quot;AllOrigins&quot;,
          builder =&gt;
          {
              builder.AllowAnyMethod()
                     .AllowAnyHeader()
                     .AllowAnyOrigin();
          });
      });
      services.AddScoped&lt;IClaimsTransformation, WebAppCalimsTransformation&gt;();
      services.AddAuthentication(options =&gt;
      {
          options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
          options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
      }).AddJwtBearer(o =&gt;
      {
          o.Authority = Configuration.GetValue&lt;string&gt;(&quot;AppSettings:Auth:ServerUrl&quot;);
          o.Audience = Configuration.GetValue&lt;string&gt;(&quot;AppSettings:Auth:Audience&quot;);
          o.RequireHttpsMetadata = false;
          o.Events = new JwtBearerEvents
          {
              OnTokenValidated = context =&gt;
              {
                  if (context.SecurityToken is JwtSecurityToken accessToken &amp;&amp; context.Principal.Identity is ClaimsIdentity identity)
                  {
                      identity.AddClaim(new Claim(&quot;access_token&quot;, accessToken.RawData));
                  }
  
                  return Task.CompletedTask;
              }
          };
      });
  
      services.AddAuthorization(options =&gt;
      {
          options.AddPolicy(&quot;ApiReader&quot;, policy =&gt; policy.RequireClaim(&quot;scope&quot;, &quot;my_api_software&quot;));
          options.AddPolicy(&quot;admin&quot;, policy =&gt; policy.RequireClaim(ClaimTypes.Role, &quot;admin&quot;));
          options.AddPolicy(&quot;user&quot;, policy =&gt; policy.RequireClaim(ClaimTypes.Role, &quot;user&quot;));
      });
  
      services.AddHttpClient(&quot;Auth&quot;, config =&gt;
      {
          config.BaseAddress = new Uri(Configuration.GetValue&lt;string&gt;(&quot;AppSettings:Auth:ServerUrl&quot;));
      });
  
      // In production, the React files will be served from this directory
      services.AddSpaStaticFiles(configuration =&gt;
      {
          configuration.RootPath = &quot;ClientApp/build&quot;;
      });
  
  
      services.AddSwaggerDocument(config =&gt; {
          config.OperationProcessors.Add(new OperationSecurityScopeProcessor(&quot;JWT token&quot;));
          config.AddSecurity(&quot;JWT token&quot;, new OpenApiSecurityScheme
          {
              Type = OpenApiSecuritySchemeType.ApiKey,
              Name = &quot;Authorization&quot;,
              Description = &quot;Copy 'Bearer ' + valid JWT token into field&quot;,
              In = OpenApiSecurityApiKeyLocation.Header
          });
          config.PostProcess = (document) =&gt;
          {
              document.Info.Version = &quot;v1&quot;;
              document.Info.Title = &quot;My API API&quot;;
              document.Info.Description = &quot;ASP.NET 5.0 My API&quot;;
          };
      });
  }
  </code></pre>
  <p>This is also working fine when deploying local IIS in my pc</p>