如何啓動ASP.NET Core with the dotnet CLI samples以便它們不聽本地主機?如何啓動不聽本地主機的ASP.NET Core 1.0 RC2應用程序
此命令不起作用:
dotnet run --server.urls=http://*:5000
如何啓動ASP.NET Core with the dotnet CLI samples以便它們不聽本地主機?如何啓動不聽本地主機的ASP.NET Core 1.0 RC2應用程序
此命令不起作用:
dotnet run --server.urls=http://*:5000
什麼你試圖做需要你的命令行參數添加到您的配置在你的應用程序的Main
方法。加入這樣的事情你創建你WebHostBuilder
對象之前:
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
,然後它調用.Build()
在此之前添加到WebHostBuilder
對象:
.UseConfiguration(config)
您還需要添加一個依賴到project.json:
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc2-final",
最後,添加使用的聲明,說明你的Main
方法是在文件:
using Microsoft.Extensions.Configuration;
例Main
方法:
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseConfiguration(config)
.UseStartup<Startup>()
.Build();
host.Run();
}
你也可以在代碼中直接配置url,就像[this samle](https://github.com/aspnet/KestrelHttpServer/blob/dev/samples/SampleApp/Startup.cs)一樣:'.UseKestrel()。UseUrls 「http:// *:5000」)' – qbik
是的,但他的例子試圖使用命令行。 –
你說的「不工作」是什麼意思? – Raptor