How can I specify using dotnet cli to run my web app using specific configurations. I know hosting.json can be used but I did not find any documentation how to do this and how this relates to the dotnet cli.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Look at this sample: https://github.com/aspnet/Security/blob/dev/samples/CookieSample/Program.cs#L11
Tweaked for command line:
public static void Main(string[] args)
{
var config = new ConfigurationBuilder().AddCommandLine(args).Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
Then call dotnet run server.urls=http://localhost:5001/
回答2:
Try .UseUrls
on Program.cs with specific port.
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseUrls("http://localhost:5020")
.Build();
host.Run();
}
}