2016-08-23 75 views
3

我有以下入口點:無法從命令行更改隼監聽端口

public static void Main(string[] args) 
{ 
    var config = new ConfigurationBuilder() 
     .SetBasePath(Directory.GetCurrentDirectory()) 
     .AddJsonFile("hosting.json", optional: true) 
     .AddCommandLine(args) 
     .AddEnvironmentVariables() 
     .Build(); 

    var host = new WebHostBuilder() 
     .UseConfiguration(config) 
     .UseKestrel() 
     .UseContentRoot(Directory.GetCurrentDirectory()) 
     .UseIISIntegration() 
     .UseStartup<Startup>() 
     .Build(); 

    host.Run(); 
} 

它的工作原理,如果我添加hosting.json文件中像

{ 
    "server.urls": "http://0.0.0.0:5001" 
} 

,或者如果我定義的環境變量(有發現名稱here

SET ASPNETCORE_URLS=https://0.0.0.0:5001 

但是,如果我通過--server.urls http://0.0.0.0:5001爲paramete R,應用程序偵聽默認端口5000:

> dotnet run --server.urls http://0.0.0.0:5001 
... 
Now listening on: http://localhost:5000 
+0

你使用的是什麼確切版本的dotnet? –

+0

@DirkVollmar dotnet --version返回1.0.0-preview2-003121 – Set

+0

請嘗試更新到最新版本,然後(如果Oleg的答案尚未解決您的問題)。 –

回答

2

正確的語法是

dotnet run --server.urls=http://0.0.0.0:5001 

,而不是

dotnet run --server.urls http://0.0.0.0:5001 

詳情請參閱the old answer

+2

仍在監聽默認端口 – Set

+1

@Set你確定你通過了'--server.urls = http://0.0.0.0:5002'嗎?在你更新的問題中,你使用'--server.url'(用's'')。 –

+0

是錯誤打印(謝謝,問題已解決) – Set