Hello i need to use the appsettings
(or another jsonfile) before the Startup
class is initialized , specifically in the CreateWebHostBuilder
that is called in Program.Main
. I want to set the UseUrls(url)
for the application.
I want to somehow reuse the same resource when using the IConfiguration
in the Startup
class.
How can achieve this ?
public class Program {
public static void Main(string[] args) {
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
WebHostBuilder builder = new WebHostBuilder();
builder.UseStartup<Startup>();
//load the Port and Host from appsettings
var url =$"http://{appsettings.host}:{appsettings.port}/";
Debug.WriteLine(url);
builder.UseKestrel().UseUrls(url);
return builder;
}
}