两个Kestrel进程可以侦听同一域中的不同URL吗?

时间:2017-07-08 23:16:39

标签: asp.net-mvc asp.net-core

假设我有两个名为“a”和“b”的应用程序。如何让它们同时在不同虚拟目录下的同一域上运行?

身份应该听取http://localhost:8080/a/

var host = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseUrls($"http://*:8080/a/")
    .UseStartup<Startup>()
    .Build();
host.Run();

Userprofiles应该在http://localhost:8080/userprofiles/

上收听
var host = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseUrls($"http://*:8080/b/")
    .UseStartup<Startup>()
    .Build();
host.Run();

应用程序单独运行,但是当我同时启动它们时出现此错误

crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http:/ /*:8080/userprofiles: address already in use. ---> System.AggregateException: One or more errors occurred. 
(Error -4091 EADDRINUSE address already in use) ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -4091 EADDRINUSE address already in use
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.ThrowError(Int32 statusCode)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_getsockname(UvTcpHandle handle, SockAddr& addr, Int32& namelen)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.GetSockIPEndPoint()

1 个答案:

答案 0 :(得分:2)

Kestrel无法本机共享端口。您可以在IIS后面运行它并执行此操作,或者您可以使用WebListener。