Kestrel和ASP.NET Core MVC使用自定义基本路径

ryu*_*ice 7 asp.net-web-api asp.net-core-mvc kestrel-http-server asp.net-core

如何将应用程序安装在不同的基本路径上?

例如,我的控制器的路由是/ api/keywords,但是当运行Web服务器时,我希望basepath是/ development,所以我的控制器路由是/ development/api/keywords.我宁愿不必修改我的控制器.在旧的Web API版本中,您可以在不同的路径中安装OWIN应用程序,因此我希望执行类似的操作.

Tra*_*her 7

有一种名为UsePathBase的新方法可以轻松完成. https://github.com/aspnet/HttpAbstractions/blob/bfa183747f6fb528087554c3d6ec58ef05f1c10a/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/UsePathBaseExtensions.cs

  • 由于链接的存储库已存档,因此这是新链接 https://github.com/aspnet/AspNetCore/blob/master/src/Http/Http.Abstractions/src/Extensions/UsePathBaseExtensions.cs。只需在“Startup.Configure”方法中使用“app.UsePathBase(new PathString("/path"))”即可。 (2认同)