如何启动不侦听本地主机的 ASP.NET Core 1.0 RC2 应用程序 [英] How to start a ASP.NET Core 1.0 RC2 app that doesn't listen to the localhost
问题描述
如何使用 dotnet CLI 示例启动 ASP.NET Core 以便它们不不听本地主机?
how can I start the ASP.NET Core with the dotnet CLI samples so that they don't listen to the localhost?
此命令不起作用:
dotnet run --server.urls=http://*:5000
推荐答案
您尝试执行的操作要求您在应用程序的 Main
方法中将命令行参数添加到您的配置中.在创建 WebHostBuilder
对象之前添加如下内容:
What you're trying to do requires you to add command-line args to your configuration in the Main
method of your application. Add something like this before you create your WebHostBuilder
object:
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
然后在对它调用 .Build()
之前将它添加到 WebHostBuilder
对象:
And then add this to the WebHostBuilder
object before calling .Build()
on it:
.UseConfiguration(config)
您还需要向 project.json 添加依赖项:
You'll also need to add a dependency to project.json:
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc2-final",
最后,在 Main
方法所在的文件中添加一个 using 语句:
And finally, add a using statement to the file that your Main
method is in:
使用 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();
}
这篇关于如何启动不侦听本地主机的 ASP.NET Core 1.0 RC2 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!