© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•16mo ago•
7 replies
Camster

User Secrets in Blazor Web Assembly

I have a Blazor Web Assembly app that can connect to a production API on the web or a development API on the local machine. The Program.cs file looks like this:
builder.Services.AddHttpClient<IClient, Client>(x => new Client("https://www.productionapi.com", x));
//builder.Services.AddHttpClient<IClient, Client>(x => new Client("https://localhost:1234", x));
builder.Services.AddHttpClient<IClient, Client>(x => new Client("https://www.productionapi.com", x));
//builder.Services.AddHttpClient<IClient, Client>(x => new Client("https://localhost:1234", x));


Whenever I want to switch between the two, I have to edit the file, and sometimes I forgot I need to undo the change before checking in.

My question is: Is it possible to use User Secrets to make this easy switch while I'm testing? I can already to that in other code bases, but since this is Web Assembly and doesn't have AppSettings, I'm not sure how to do it here.

Thank you for your help.
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Blazor web assembly app
C#CC# / help
2y ago
Blazor server vs. Blazor web assembly + Minimal API
C#CC# / help
3y ago
Blazor Web Assembly and Windows Authentication
C#CC# / help
5mo ago
How to implement Authentication in Blazor Web Assembly?
C#CC# / help
8mo ago