{"record":{"id":"2aaec565dbe45efd","repo":"dotnet/AspNetCore.Docs","slug":"no-uri","errorCode":null,"errorMessage":"No URI!","messagePattern":"No URI!","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"aspnetcore/blazor/security/additional-scenarios.md","lineNumber":180,"sourceCode":"builder.Services.AddHttpClient(\"{HTTP CLIENT NAME}\",\n      client => client.BaseAddress = new Uri(\"{BASE ADDRESS}\"))\n      .AddHttpMessageHandler<TokenHandler>();\n```\n\nExample:\n\n```csharp\nbuilder.Services.AddScoped<TokenHandler>();\n\nbuilder.Services.AddHttpClient(\"ExternalApi\",\n      client => client.BaseAddress = new Uri(\"https://localhost:7277\"))\n      .AddHttpMessageHandler<TokenHandler>();\n```\n\nYou can supply the HTTP client base address from [configuration](xref:blazor/fundamentals/configuration) with `builder.Configuration[\"{CONFIGURATION KEY}\"]`, where the `{CONFIGURATION KEY}` placeholder is the configuration key:\n\n```csharp\nnew Uri(builder.Configuration[\"ExternalApiUri\"] ?? throw new IOException(\"No URI!\"))\n```\n\nIn `appsettings.json`, specify the `ExternalApiUri`. The following example sets the value to the localhost address of the external web API to `https://localhost:7277`:\n\n```json\n\"ExternalApiUri\": \"https://localhost:7277\"\n```\n\nAt this point, an <xref:System.Net.Http.HttpClient> created by a component can make secure web API requests. In the following example, the `{REQUEST URI}` is the relative request URI, and the `{HTTP CLIENT NAME}` placeholder is the name of the <xref:System.Net.Http.HttpClient>:\n\n```csharp\nusing var request = new HttpRequestMessage(HttpMethod.Get, \"{REQUEST URI}\");\nvar client = ClientFactory.CreateClient(\"{HTTP CLIENT NAME}\");\nusing var response = await client.SendAsync(request);\n```\n\nExample:\n","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/blazor/security/additional-scenarios.md#L162-L198","documentation":"IOException(\"No URI!\") thrown inline when constructing the HttpClient BaseAddress if builder.Configuration[\"ExternalApiUri\"] is null. Unlike error 54 (which throws a generic Exception), this variant throws IOException, signaling an I/O/configuration problem with the external API endpoint. Fails at startup/DI registration so the missing URI is caught immediately.","triggerScenarios":"ExternalApiUri configuration value is absent from appsettings.json, environment variables, or user secrets when AddHttpClient's configuration delegate executes.","commonSituations":"Missing ExternalApiUri in a deployment environment; key renamed without updating code; local dev without user-secrets; CI/test environment without the variable set.","solutions":["Add \"ExternalApiUri\": \"https://localhost:7277\" (or production URL) to appsettings.json or the per-environment appsettings.","Set the ExternalApiUri environment variable in Production.","Set a user-secret in Development: dotnet user-secrets set \"ExternalApiUri\" \"https://localhost:7277\".","Validate configuration keys at startup to surface missing values with a precise message."],"exampleFix":"// before\nnew Uri(builder.Configuration[\"ExternalApiUri\"] ?? throw new IOException(\"No URI!\"))\n\n// after — validated config with clear guidance\nvar externalApiUri = builder.Configuration[\"ExternalApiUri\"]\n    ?? throw new InvalidOperationException(\n        \"Configuration key 'ExternalApiUri' is missing. \" +\n        \"Set it in appsettings.json, user-secrets, or an environment variable.\");\nclient.BaseAddress = new Uri(externalApiUri);","handlingStrategy":"validation","validationCode":"var uri = builder.Configuration[\"ExternalApiUri\"];\nif (!Uri.TryCreate(uri, UriKind.Absolute, out _)) {\n    throw new InvalidOperationException(\"Configure a valid 'ExternalApiUri'.\");\n}","typeGuard":"static bool IsValidUri(string? s) => Uri.TryCreate(s, UriKind.Absolute, out _);","tryCatchPattern":"try { /* startup */ }\ncatch (IOException ex) when (ex.Message.Contains(\"No URI\"))\n{\n    host.LogCritical(\"ExternalApiUri not configured.\");\n    throw;\n}","preventionTips":["Add ExternalApiUri to appsettings per environment.","Set the value as an environment variable in Production.","Use user-secrets in Development.","Validate configuration keys at startup."],"tags":["blazor","httpclient","configuration","dependency-injection","secrets"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}