Summary
Blazor WebAssembly Hosted app deployed to IIS fails to resolve API endpoints after Azure DevOps token replacement. The issue arises from incorrect configuration of BaseUri and relative endpoints, leading to 404/500 errors despite successful token replacement.
Root Cause
- Incorrect
BaseUriformat: Missing scheme (https://) and inconsistent trailing slashes. - Misconfigured
HttpClient.BaseAddress: Not set or incorrectly set in the client or server. - Runtime configuration loading: Blazor WASM client may not load
appsettings.jsonfromwwwrootas expected.
Why This Happens in Real Systems
- Token replacement limitations: Replaces values but doesn’t validate configuration correctness.
- Blazor WASM architecture: Client and server configurations are independent, requiring careful coordination.
- IIS deployment nuances: File structure and runtime behavior differ from development environments.
Real-World Impact
- Service downtime: API calls fail, rendering the app unusable.
- Debugging complexity: Token replacement success masks the underlying configuration issue.
- User frustration: Unexpected errors degrade user experience.
Example or Code (if necessary and relevant)
// Correct HttpClient configuration in Client Program.cs
var client = new HttpClient();
client.BaseAddress = new Uri("https://devmyapp.com/");
services.AddScoped(sp => client);
How Senior Engineers Fix It
- Include scheme and trailing slash in
AppBaseUri:"https://devmyapp.com/". - Set
HttpClient.BaseAddressin the client’sProgram.csusing theAppBaseUrifrom configuration. - Verify runtime configuration loading: Ensure Blazor WASM loads
appsettings.jsonfromwwwrootcorrectly. - Test relative URLs: Combine
BaseUriwith relative endpoints programmatically to avoid hardcoding.
Why Juniors Miss It
- Assumed token replacement suffices: Focus on replacement success without validating runtime behavior.
- Overlooked Blazor WASM specifics: Misunderstand how the client loads configuration and handles
BaseAddress. - Ignored IIS deployment quirks: Assume development and production environments behave identically.