在asp.net web api中,可以将具有特定端口的路由映射到控制器,如下所示:
public void Run1()
{
HttpConfiguration config = new HttpConfiguration();
...
config.Routes.MapHttpRoute(
name: "Controller1",
routeTemplate: "{action}",
defaults: new { controller = "Controller1" }
);
Microsoft.Owin.Hosting.WebApp.Start("http://localhost:9000/base1/", config);
}
public void Run2()
{
HttpConfiguration config = new HttpConfiguration();
...
config.Routes.MapHttpRoute(
name: "Controller2",
routeTemplate: "{action}",
defaults: new { controller = "Controller3" }
);
Microsoft.Owin.Hosting.WebApp.Start("http://localhost:9000/base2/", config);
}
public void Run3()
{
HttpConfiguration config = new HttpConfiguration();
...
config.Routes.MapHttpRoute(
name: "Controller3",
routeTemplate: "{action}",
defaults: new { controller = "Controller3" }
);
Microsoft.Owin.Hosting.WebApp.Start("http://localhost:9050/base3/", config);
}
Run1();
Run2();
Run3();
这给出了三条不同的路线:
http://localhost:9000/base1/SomeAction -> SomeAction on Controller1
http://localhost:9000/base2/SomeAction -> SomeAction on Controller2
http://localhost:9050/base3/SomeAction -> SomeAction on Controller3
如何在asp.net核心中使用Kestrel来完成这项工作?
我知道,我可以使用 IWebHostBuilder.UseUrls 指定Kestrel侦听的端口,使用 IApplicationBuilder.UsePathBase 指定基本路径。但是如何将路线映射到特定端口?
此外:似乎Kestrel(与Katana相反)不能在同一个端口上运行多次(参见Run1和Run2)。有人可以证实吗?