Search code examples
asp.net-web-apiasp.net-coreasp.net-core-mvckestrel-http-server

Kestrel and ASP.NET Core MVC use custom base path


How can you mount your app on a different base path?

For example, my controller's route is /api/keywords, but when running the web server I want the basepath to be /development, so my controller route would be /development/api/keywords. I would rather not have to modify my controllers. In old Web API versions you could mount an OWIN app in a different path so I'm looking to do something similar.


Solution

  • There's a new method called UsePathBase that can do this easily. https://github.com/aspnet/HttpAbstractions/blob/bfa183747f6fb528087554c3d6ec58ef05f1c10a/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/UsePathBaseExtensions.cs