0

In Program.cs I read a configuration var like this:

var builder = WebApplication.CreateBuilder(args);
var host = builder.Configuration["host"]

In my development I need this var to be http://localhost/myapp

but when I publish (using VS2022 publish) to production I need it to be https://www.example.com

I tried creating multiple appsettings.json, .. appsettings.envName.json files, but when I publish they all get copied as is to the publish folder, regardless of what <EnvironmentName>envName</EnvironmentName> I have in the publish .pubxml file.

buga
  • 852
  • 9
  • 21
  • Where is the code about URLs? You can use the UseUrls extension method on the WebApplicationBuilder object in Program.cs. Refer to https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-7.0#urls. For setting up URLs in a development or production environment, you can refer to this tutorial: https://andrewlock.net/5-ways-to-set-the-urls-for-an-aspnetcore-app/. – TengFeiXie May 03 '23 at 10:03

0 Answers0