I am working with Blazor Wasm on .NET 8. I am attempting to publish my app to the dev server and QA server for the first time. I am running into an issue where all my API calls are failing. Looking at the network trace, I can see that my base url for the API is being cut off.
My base url is something like this :
"BaseFakeApiUrl": "https://dev.FakeSite.com/IisSiteName"So in this example the /IisSiteName is being cut off. I did make changes to the url (added a 2 to FakeSite) to verify I am in the right file and I am. I also tried adding a / after IisSiteName.
I am at a loss as to why the iis site name is being cut off, any guidance would be appreciated.
Edit: I noticed that appsettings.json shows in my network trace, first it shows appsettings.development.json and checking the preview it has the correct url set for the base url. Then it loads appsettings.json which did not. I changed it so that it does have the correct url which is reflected in my network trace but the API call is still missing the IIS Site Name
Edit 2: Here is how i am using it
I have my appsettings.development.json (i confirmed this is being used by adding a 2 to the sub domain and checking that it appeared in the network trace)
{"Logging": {"LogLevel": {"Default": "Information","Microsoft.AspNetCore": "Warning" } },"AllowedHosts": "*","BaseServiceCompanyApiUrl": "https://dev.test.com/IisSiteName"}I use the app settings in Program.cs to inject a HttpClient that has the base url
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.Configuration.GetValue<string>("BaseServiceCompanyApiUrl")) });builder.Services.AddHttpClient<ServiceCompanyServices>(x => { x.BaseAddress = new Uri(builder.Configuration.GetValue<string>("BaseServiceCompanyApiUrl")); });builder.Services.AddHttpClient<AuthorizationService>(x => { x.BaseAddress = new Uri(builder.Configuration.GetValue<string>("BaseServiceCompanyApiUrl")); });And then in my Service I do this
public class AuthorizationService{ private readonly HttpClient client; public AuthorizationService(HttpClient client) { this.client = client; } public async Task<UserAuthInfo>GetUserAuthInfo() { var url = "/Authenticate/GetUserAuthInfo"; return await GenericApiServices.GetFromAPI<UserAuthInfo>(client, url); }}When the GetUesrAuthInfo() is used i can see in the network trace that it is calling https://dev.test.com/Authenticate/GetUserInfo , notice that it is missing the /IisSiteName from the base url.
Edit 3. I realized i did not includ the GenericApi method so here it is. Note that when debugging the url is correct when calling the GetAsync()
public static class GenericApiServices { public static async Task<T> GetFromAPI<T>(HttpClient client, string url) { var response = await client.GetAsync(url); if (response.IsSuccessStatusCode) return await response.Content.ReadFromJsonAsync<T>(); else if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { Console.WriteLine("Throwing File Not Found Exception"); var errorMessage = await response.Content.ReadFromJsonAsync<string>(); if (String.IsNullOrEmpty(errorMessage)) errorMessage = "File Not Found"; throw new FileNotFoundException(errorMessage); } else { var errorMessage = await response.Content.ReadFromJsonAsync<string>(); if (String.IsNullOrEmpty(errorMessage)) errorMessage = "An Error occured."; throw new Exception(errorMessage); } }