Asp.net core VS 2015是否使用红隼?
我正在使用VS 2015更新3。 我有ASP.NET核心web api和以下Program.cs代码Asp.net core VS 2015是否使用红隼?,asp.net-core,asp.net-core-1.0,coreclr,kestrel-http-server,Asp.net Core,Asp.net Core 1.0,Coreclr,Kestrel Http Server,我正在使用VS 2015更新3。 我有ASP.NET核心web api和以下Program.cs代码 public class Program { public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseUrls("http://*:5000")
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls("http://*:5000")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
然后我按F5使用VisualStudio运行应用程序。当我向API发出请求时,我会返回结果,以便一切正常。在Program.cs中,我有
.useisintegration()
。所以,我的印象是,当请求来到IIS express时,它只是将该请求转发给Kestrel。
所以我认为IIS Express和Kestrel必须同时在两个不同的端口上运行
然而,当我运行netstat-ab
命令时,我注意到IIS express按预期在端口40000上运行,但在端口5000上没有运行任何东西。事实上,为了进行测试,我将IIS Express端口也更改为5000
,并且运行良好。我原以为IIS Express和Kestrel之间会发生冲突,但那没有发生
所以问题是VS 2015是否使用了红隼?VisualStudio确实使用了红隼。诀窍是当Kestrel在IIS/IISExpress后面使用时,它没有使用您指定的端口。相反,IIS选择一个随机端口,它将用于通信,这是Kestrel必须使用的端口(该端口在UseIISIntegration
中被覆盖)。如果您直接运行Kestrel。UseIISIntegration
只是一个no操作,因此Kestrel将侦听您在UseUrls
中指定的端口。这样做的后果之一是,.useURL
和.useisintegration
的顺序很重要-如果您将.useURL
放在之后。useisintegration
您将始终覆盖端口,因此您将无法使用IIS启动应用程序。
如果你想知道到底发生了什么,请看一看我在这个主题上写的一篇文章
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:40000/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/workunit",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000/api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}